Skip to content

Commit

Permalink
Merge pull request #771 from iRevive/semconv/metrics-use-attributes
Browse files Browse the repository at this point in the history
semconv-metrics: use a reference to semantic attributes
  • Loading branch information
iRevive authored Sep 11, 2024
2 parents 87b7652 + e10859e commit 15e2ccb
Show file tree
Hide file tree
Showing 14 changed files with 353 additions and 310 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ lazy val `semconv-metrics-stable` =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("semconv/metrics/stable"))
.dependsOn(`core-metrics`)
.dependsOn(`core-metrics`, `semconv-stable`)
.settings(
name := "otel4s-semconv-metrics",
startYear := Some(2024),
Expand All @@ -644,7 +644,7 @@ lazy val `semconv-metrics-experimental` =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("semconv/metrics/experimental"))
.dependsOn(`core-metrics`, `semconv-metrics-stable`)
.dependsOn(`core-metrics`, `semconv-metrics-stable`, `semconv-experimental`)
.settings(
name := "otel4s-semconv-metrics-experimental",
startYear := Some(2024),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
{%- endif -%}
{% endmacro %}

{%- macro attributeRef(attribute) -%}
{%- if attribute is stable -%}
{{ attribute.name.split(".")[0] | pascal_case }}Attributes.{{ attribute.name | pascal_case }}
{%- else -%}
{{ attribute.name.split(".")[0] | pascal_case }}ExperimentalAttributes.{{ attribute.name | pascal_case }}
{%- endif -%}
{%- endmacro -%}

{%- set object_name = ctx.root_namespace | pascal_case ~ params.object_prefix ~ "Metrics" -%}

/*
Expand Down Expand Up @@ -80,6 +88,22 @@ package metrics
{%- endif %}

import org.typelevel.otel4s.metrics._
{%- set required_imports = namespace(stable = false, experimental = false) -%}
{%- for metric in ctx.metrics -%}
{% for attribute in metric.attributes %}
{%- if attribute is stable -%}
{%- set required_imports.stable = true -%}
{%- else -%}
{%- set required_imports.experimental = true -%}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{%- if required_imports.stable == true %}
import org.typelevel.otel4s.semconv.attributes._
{%- endif %}
{%- if required_imports.experimental == true %}
import org.typelevel.otel4s.semconv.experimental.attributes._
{%- endif %}

// DO NOT EDIT, this is an Auto-generated file from buildscripts/templates/registry/otel4s/metrics/SemanticMetrics.scala.j2
object {{ object_name }} {
Expand All @@ -103,7 +127,7 @@ object {{ object_name }} {
{%- endif %}
val {{ attribute.name | camel_case }}: AttributeSpec[{{to_scala_key_type(attribute)}}] =
AttributeSpec(
AttributeKey("{{attribute.name}}"),
{{ attributeRef(attribute) }},
List(
{% for example in attribute.examples -%} {{ exampleValue(attribute.type | instantiated_type, example) }}, {% endfor %}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package experimental
package metrics

import org.typelevel.otel4s.metrics._
import org.typelevel.otel4s.semconv.experimental.attributes._

// DO NOT EDIT, this is an Auto-generated file from buildscripts/templates/registry/otel4s/metrics/SemanticMetrics.scala.j2
object ContainerExperimentalMetrics {
Expand All @@ -43,7 +44,7 @@ object ContainerExperimentalMetrics {
*/
val cpuMode: AttributeSpec[String] =
AttributeSpec(
AttributeKey("cpu.mode"),
CpuExperimentalAttributes.CpuMode,
List(
"user",
"system",
Expand Down Expand Up @@ -83,7 +84,7 @@ object ContainerExperimentalMetrics {
*/
val diskIoDirection: AttributeSpec[String] =
AttributeSpec(
AttributeKey("disk.io.direction"),
DiskExperimentalAttributes.DiskIoDirection,
List(
"read",
),
Expand All @@ -95,7 +96,7 @@ object ContainerExperimentalMetrics {
*/
val systemDevice: AttributeSpec[String] =
AttributeSpec(
AttributeKey("system.device"),
SystemExperimentalAttributes.SystemDevice,
List(
"(identifier)",
),
Expand Down Expand Up @@ -154,7 +155,7 @@ object ContainerExperimentalMetrics {
*/
val networkIoDirection: AttributeSpec[String] =
AttributeSpec(
AttributeKey("network.io.direction"),
NetworkExperimentalAttributes.NetworkIoDirection,
List(
"transmit",
),
Expand All @@ -166,7 +167,7 @@ object ContainerExperimentalMetrics {
*/
val systemDevice: AttributeSpec[String] =
AttributeSpec(
AttributeKey("system.device"),
SystemExperimentalAttributes.SystemDevice,
List(
"(identifier)",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package experimental
package metrics

import org.typelevel.otel4s.metrics._
import org.typelevel.otel4s.semconv.attributes._
import org.typelevel.otel4s.semconv.experimental.attributes._

// DO NOT EDIT, this is an Auto-generated file from buildscripts/templates/registry/otel4s/metrics/SemanticMetrics.scala.j2
object DbExperimentalMetrics {
Expand All @@ -42,7 +44,7 @@ object DbExperimentalMetrics {
*/
val dbClientConnectionPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connection.pool.name"),
DbExperimentalAttributes.DbClientConnectionPoolName,
List(
"myDataSource",
),
Expand All @@ -54,7 +56,7 @@ object DbExperimentalMetrics {
*/
val dbClientConnectionState: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connection.state"),
DbExperimentalAttributes.DbClientConnectionState,
List(
"idle",
),
Expand Down Expand Up @@ -96,7 +98,7 @@ object DbExperimentalMetrics {
*/
val dbClientConnectionPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connection.pool.name"),
DbExperimentalAttributes.DbClientConnectionPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -138,7 +140,7 @@ object DbExperimentalMetrics {
*/
val dbClientConnectionPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connection.pool.name"),
DbExperimentalAttributes.DbClientConnectionPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -179,7 +181,7 @@ object DbExperimentalMetrics {
*/
val dbClientConnectionPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connection.pool.name"),
DbExperimentalAttributes.DbClientConnectionPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -220,7 +222,7 @@ object DbExperimentalMetrics {
*/
val dbClientConnectionPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connection.pool.name"),
DbExperimentalAttributes.DbClientConnectionPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -261,7 +263,7 @@ object DbExperimentalMetrics {
*/
val dbClientConnectionPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connection.pool.name"),
DbExperimentalAttributes.DbClientConnectionPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -302,7 +304,7 @@ object DbExperimentalMetrics {
*/
val dbClientConnectionPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connection.pool.name"),
DbExperimentalAttributes.DbClientConnectionPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -343,7 +345,7 @@ object DbExperimentalMetrics {
*/
val dbClientConnectionPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connection.pool.name"),
DbExperimentalAttributes.DbClientConnectionPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -385,7 +387,7 @@ object DbExperimentalMetrics {
*/
val dbClientConnectionPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connection.pool.name"),
DbExperimentalAttributes.DbClientConnectionPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -426,7 +428,7 @@ object DbExperimentalMetrics {
@deprecated("Replaced by `db.client.connection.pool.name`.", "")
val dbClientConnectionsPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connections.pool.name"),
DbExperimentalAttributes.DbClientConnectionsPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -466,7 +468,7 @@ object DbExperimentalMetrics {
@deprecated("Replaced by `db.client.connection.pool.name`.", "")
val dbClientConnectionsPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connections.pool.name"),
DbExperimentalAttributes.DbClientConnectionsPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -505,7 +507,7 @@ object DbExperimentalMetrics {
@deprecated("Replaced by `db.client.connection.pool.name`.", "")
val dbClientConnectionsPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connections.pool.name"),
DbExperimentalAttributes.DbClientConnectionsPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -544,7 +546,7 @@ object DbExperimentalMetrics {
@deprecated("Replaced by `db.client.connection.pool.name`.", "")
val dbClientConnectionsPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connections.pool.name"),
DbExperimentalAttributes.DbClientConnectionsPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -583,7 +585,7 @@ object DbExperimentalMetrics {
@deprecated("Replaced by `db.client.connection.pool.name`.", "")
val dbClientConnectionsPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connections.pool.name"),
DbExperimentalAttributes.DbClientConnectionsPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -622,7 +624,7 @@ object DbExperimentalMetrics {
@deprecated("Replaced by `db.client.connection.pool.name`.", "")
val dbClientConnectionsPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connections.pool.name"),
DbExperimentalAttributes.DbClientConnectionsPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -661,7 +663,7 @@ object DbExperimentalMetrics {
@deprecated("Replaced by `db.client.connection.pool.name`.", "")
val dbClientConnectionsPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connections.pool.name"),
DbExperimentalAttributes.DbClientConnectionsPoolName,
List(
"myDataSource",
),
Expand All @@ -674,7 +676,7 @@ object DbExperimentalMetrics {
@deprecated("Replaced by `db.client.connection.state`.", "")
val dbClientConnectionsState: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connections.state"),
DbExperimentalAttributes.DbClientConnectionsState,
List(
"idle",
),
Expand Down Expand Up @@ -715,7 +717,7 @@ object DbExperimentalMetrics {
@deprecated("Replaced by `db.client.connection.pool.name`.", "")
val dbClientConnectionsPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connections.pool.name"),
DbExperimentalAttributes.DbClientConnectionsPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -756,7 +758,7 @@ object DbExperimentalMetrics {
@deprecated("Replaced by `db.client.connection.pool.name`.", "")
val dbClientConnectionsPoolName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.client.connections.pool.name"),
DbExperimentalAttributes.DbClientConnectionsPoolName,
List(
"myDataSource",
),
Expand Down Expand Up @@ -803,7 +805,7 @@ object DbExperimentalMetrics {
*/
val dbCollectionName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.collection.name"),
DbExperimentalAttributes.DbCollectionName,
List(
"public.users",
"customers",
Expand All @@ -825,7 +827,7 @@ object DbExperimentalMetrics {
*/
val dbNamespace: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.namespace"),
DbExperimentalAttributes.DbNamespace,
List(
"customers",
"test.users",
Expand All @@ -844,7 +846,7 @@ object DbExperimentalMetrics {
*/
val dbOperationName: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.operation.name"),
DbExperimentalAttributes.DbOperationName,
List(
"findAndModify",
"HMSET",
Expand All @@ -864,7 +866,7 @@ object DbExperimentalMetrics {
*/
val dbSystem: AttributeSpec[String] =
AttributeSpec(
AttributeKey("db.system"),
DbExperimentalAttributes.DbSystem,
List(
),
Requirement.required,
Expand All @@ -879,7 +881,7 @@ object DbExperimentalMetrics {
*/
val errorType: AttributeSpec[String] =
AttributeSpec(
AttributeKey("error.type"),
ErrorAttributes.ErrorType,
List(
"timeout",
"java.net.UnknownHostException",
Expand All @@ -899,7 +901,7 @@ object DbExperimentalMetrics {
*/
val networkPeerAddress: AttributeSpec[String] =
AttributeSpec(
AttributeKey("network.peer.address"),
NetworkAttributes.NetworkPeerAddress,
List(
"10.1.2.80",
"/tmp/my.sock",
Expand All @@ -912,7 +914,7 @@ object DbExperimentalMetrics {
*/
val networkPeerPort: AttributeSpec[Long] =
AttributeSpec(
AttributeKey("network.peer.port"),
NetworkAttributes.NetworkPeerPort,
List(
65123,
),
Expand All @@ -927,7 +929,7 @@ object DbExperimentalMetrics {
*/
val serverAddress: AttributeSpec[String] =
AttributeSpec(
AttributeKey("server.address"),
ServerAttributes.ServerAddress,
List(
"example.com",
"10.1.2.80",
Expand All @@ -944,7 +946,7 @@ object DbExperimentalMetrics {
*/
val serverPort: AttributeSpec[Long] =
AttributeSpec(
AttributeKey("server.port"),
ServerAttributes.ServerPort,
List(
80,
8080,
Expand Down
Loading

0 comments on commit 15e2ccb

Please sign in to comment.