From e3d0e464b128ed82287f2414190e6ae19cf75e20 Mon Sep 17 00:00:00 2001 From: Bryan Naegele Date: Mon, 29 Jul 2024 13:44:44 -0600 Subject: [PATCH] Include stable attrs in incubating --- .../incubating/attributes/http_attributes.hrl | 2 ++ .../attributes/messaging_attributes.hrl | 2 ++ .../incubating/attributes/network_attributes.hrl | 2 ++ .../incubating/attributes/service_attributes.hrl | 2 ++ .../attributes/telemetry_attributes.hrl | 2 ++ .../incubating/attributes/url_attributes.hrl | 2 ++ .../attributes/user_agent_attributes.hrl | 2 ++ .../lib/incubating/attributes/http_attributes.ex | 13 +++++++++++++ .../incubating/attributes/network_attributes.ex | 15 +++++++++++++++ .../incubating/attributes/service_attributes.ex | 3 +++ .../incubating/attributes/telemetry_attributes.ex | 5 +++++ .../lib/incubating/attributes/url_attributes.ex | 9 +++++++++ .../attributes/user_agent_attributes.ex | 1 + .../registry/elixir/semantic_attributes.ex.j2 | 13 +++++++++++-- .../templates/registry/elixir/weaver.yaml | 1 + .../registry/erlang/semantic_attributes.hrl.j2 | 4 +++- .../templates/registry/erlang/weaver.yaml | 1 + .../semantic_conventions/sem_conv_test.exs | 5 +++++ .../test/opentelemetry_semconv_SUITE.erl | 2 ++ 19 files changed, 83 insertions(+), 3 deletions(-) diff --git a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/http_attributes.hrl b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/http_attributes.hrl index 094cf38b..3a7f3c7a 100644 --- a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/http_attributes.hrl +++ b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/http_attributes.hrl @@ -13,6 +13,8 @@ %% See the License for the specific language governing permissions and %% limitations under the License. %%%------------------------------------------------------------------------- +-include("attributes/http_attributes.hrl"). + %% @deprecated Replaced by `client.address`. %% Deprecated, use `client.address` instead. -define('HTTP_CLIENT_IP', 'http.client_ip'). diff --git a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/messaging_attributes.hrl b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/messaging_attributes.hrl index 401e5c77..3b018a16 100644 --- a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/messaging_attributes.hrl +++ b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/messaging_attributes.hrl @@ -13,6 +13,8 @@ %% See the License for the specific language governing permissions and %% limitations under the License. %%%------------------------------------------------------------------------- +-include("attributes/messaging_attributes.hrl"). + %% The number of messages sent, received, or processed in the scope of the batching operation. -define('MESSAGING_BATCH_MESSAGE_COUNT', 'messaging.batch.message_count'). diff --git a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/network_attributes.hrl b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/network_attributes.hrl index a0dec359..09f5fe71 100644 --- a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/network_attributes.hrl +++ b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/network_attributes.hrl @@ -13,6 +13,8 @@ %% See the License for the specific language governing permissions and %% limitations under the License. %%%------------------------------------------------------------------------- +-include("attributes/network_attributes.hrl"). + %% @deprecated Replaced by `network.local.address`. %% Deprecated, use `network.local.address`. -define('NET_HOST_IP', 'net.host.ip'). diff --git a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/service_attributes.hrl b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/service_attributes.hrl index e5f1ef20..055cd97b 100644 --- a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/service_attributes.hrl +++ b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/service_attributes.hrl @@ -13,6 +13,8 @@ %% See the License for the specific language governing permissions and %% limitations under the License. %%%------------------------------------------------------------------------- +-include("attributes/service_attributes.hrl"). + %% The string ID of the service instance. %% diff --git a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/telemetry_attributes.hrl b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/telemetry_attributes.hrl index 574cd83b..346a5db2 100644 --- a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/telemetry_attributes.hrl +++ b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/telemetry_attributes.hrl @@ -13,6 +13,8 @@ %% See the License for the specific language governing permissions and %% limitations under the License. %%%------------------------------------------------------------------------- +-include("attributes/telemetry_attributes.hrl"). + %% The name of the auto instrumentation agent or distribution, if used. %% diff --git a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/url_attributes.hrl b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/url_attributes.hrl index 663adb01..810a8de2 100644 --- a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/url_attributes.hrl +++ b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/url_attributes.hrl @@ -13,6 +13,8 @@ %% See the License for the specific language governing permissions and %% limitations under the License. %%%------------------------------------------------------------------------- +-include("attributes/url_attributes.hrl"). + %% Domain extracted from the `url.full`, such as "opentelemetry.io". %% diff --git a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/user_agent_attributes.hrl b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/user_agent_attributes.hrl index cd2f0082..96e6c60f 100644 --- a/apps/opentelemetry_semantic_conventions/include/incubating/attributes/user_agent_attributes.hrl +++ b/apps/opentelemetry_semantic_conventions/include/incubating/attributes/user_agent_attributes.hrl @@ -13,6 +13,8 @@ %% See the License for the specific language governing permissions and %% limitations under the License. %%%------------------------------------------------------------------------- +-include("attributes/user_agent_attributes.hrl"). + %% Name of the user-agent extracted from original. Usually refers to the browser's name. %% diff --git a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/http_attributes.ex b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/http_attributes.ex index b2598321..7d213b79 100644 --- a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/http_attributes.ex +++ b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/http_attributes.ex @@ -3,6 +3,19 @@ defmodule OpenTelemetry.SemConv.Incubating.HTTPAttributes do @moduledoc """ OpenTelemetry Semantic Conventions for HTTP attributes. """ + defdelegate http_request_header(), to: OpenTelemetry.SemConv.HTTPAttributes + + defdelegate http_request_method(), to: OpenTelemetry.SemConv.HTTPAttributes + + defdelegate http_request_method_original(), to: OpenTelemetry.SemConv.HTTPAttributes + + defdelegate http_request_resend_count(), to: OpenTelemetry.SemConv.HTTPAttributes + + defdelegate http_response_header(), to: OpenTelemetry.SemConv.HTTPAttributes + + defdelegate http_response_status_code(), to: OpenTelemetry.SemConv.HTTPAttributes + + defdelegate http_route(), to: OpenTelemetry.SemConv.HTTPAttributes @deprecated """ Replaced by `client.address`. diff --git a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/network_attributes.ex b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/network_attributes.ex index 87a37913..2999e4c9 100644 --- a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/network_attributes.ex +++ b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/network_attributes.ex @@ -3,6 +3,21 @@ defmodule OpenTelemetry.SemConv.Incubating.NetworkAttributes do @moduledoc """ OpenTelemetry Semantic Conventions for Network attributes. """ + defdelegate network_local_address(), to: OpenTelemetry.SemConv.NetworkAttributes + + defdelegate network_local_port(), to: OpenTelemetry.SemConv.NetworkAttributes + + defdelegate network_peer_address(), to: OpenTelemetry.SemConv.NetworkAttributes + + defdelegate network_peer_port(), to: OpenTelemetry.SemConv.NetworkAttributes + + defdelegate network_protocol_name(), to: OpenTelemetry.SemConv.NetworkAttributes + + defdelegate network_protocol_version(), to: OpenTelemetry.SemConv.NetworkAttributes + + defdelegate network_transport(), to: OpenTelemetry.SemConv.NetworkAttributes + + defdelegate network_type(), to: OpenTelemetry.SemConv.NetworkAttributes @deprecated """ Replaced by `network.local.address`. diff --git a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/service_attributes.ex b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/service_attributes.ex index 7f62d368..e8c41a4c 100644 --- a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/service_attributes.ex +++ b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/service_attributes.ex @@ -3,6 +3,9 @@ defmodule OpenTelemetry.SemConv.Incubating.ServiceAttributes do @moduledoc """ OpenTelemetry Semantic Conventions for Service attributes. """ + defdelegate service_name(), to: OpenTelemetry.SemConv.ServiceAttributes + + defdelegate service_version(), to: OpenTelemetry.SemConv.ServiceAttributes @doc """ The string ID of the service instance. diff --git a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/telemetry_attributes.ex b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/telemetry_attributes.ex index bcd3b022..5aa6415b 100644 --- a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/telemetry_attributes.ex +++ b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/telemetry_attributes.ex @@ -3,6 +3,11 @@ defmodule OpenTelemetry.SemConv.Incubating.TelemetryAttributes do @moduledoc """ OpenTelemetry Semantic Conventions for Telemetry attributes. """ + defdelegate telemetry_sdk_language(), to: OpenTelemetry.SemConv.TelemetryAttributes + + defdelegate telemetry_sdk_name(), to: OpenTelemetry.SemConv.TelemetryAttributes + + defdelegate telemetry_sdk_version(), to: OpenTelemetry.SemConv.TelemetryAttributes @doc """ The name of the auto instrumentation agent or distribution, if used. diff --git a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/url_attributes.ex b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/url_attributes.ex index cb08089a..9f381771 100644 --- a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/url_attributes.ex +++ b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/url_attributes.ex @@ -3,6 +3,15 @@ defmodule OpenTelemetry.SemConv.Incubating.URLAttributes do @moduledoc """ OpenTelemetry Semantic Conventions for URL attributes. """ + defdelegate url_fragment(), to: OpenTelemetry.SemConv.URLAttributes + + defdelegate url_full(), to: OpenTelemetry.SemConv.URLAttributes + + defdelegate url_path(), to: OpenTelemetry.SemConv.URLAttributes + + defdelegate url_query(), to: OpenTelemetry.SemConv.URLAttributes + + defdelegate url_scheme(), to: OpenTelemetry.SemConv.URLAttributes @doc """ Domain extracted from the `url.full`, such as "opentelemetry.io". diff --git a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/user_agent_attributes.ex b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/user_agent_attributes.ex index 38974d67..8b619fd7 100644 --- a/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/user_agent_attributes.ex +++ b/apps/opentelemetry_semantic_conventions/lib/incubating/attributes/user_agent_attributes.ex @@ -3,6 +3,7 @@ defmodule OpenTelemetry.SemConv.Incubating.UserAgentAttributes do @moduledoc """ OpenTelemetry Semantic Conventions for User_Agent attributes. """ + defdelegate user_agent_original(), to: OpenTelemetry.SemConv.UserAgentAttributes @doc """ Name of the user-agent extracted from original. Usually refers to the browser's name. diff --git a/apps/opentelemetry_semantic_conventions/templates/registry/elixir/semantic_attributes.ex.j2 b/apps/opentelemetry_semantic_conventions/templates/registry/elixir/semantic_attributes.ex.j2 index 85f772e5..26e6ecaf 100644 --- a/apps/opentelemetry_semantic_conventions/templates/registry/elixir/semantic_attributes.ex.j2 +++ b/apps/opentelemetry_semantic_conventions/templates/registry/elixir/semantic_attributes.ex.j2 @@ -4,16 +4,25 @@ {{ template.set_file_name(file_name) }} {%- set module_name = ctx.id | pascal_case | acronym ~ "Attributes" -%} +{%- set incubating_module_namespace = "OpenTelemetry.SemConv.Incubating" -%} +{%- set stable_module_namespace = "OpenTelemetry.SemConv" -%} {%- if params.stability == "experimental" -%} -{%- set module_namespace = "OpenTelemetry.SemConv.Incubating" -%} +{%- set module_namespace = incubating_module_namespace -%} {%- else -%} -{%- set module_namespace = "OpenTelemetry.SemConv" -%} +{%- set module_namespace = stable_module_namespace -%} {%- endif -%} defmodule {{ module_namespace }}.{{ module_name }} do # This is an auto-generated file @moduledoc """ OpenTelemetry Semantic Conventions for {{ ctx.id | title | acronym }} attributes. """ +{%- if params.stability == "experimental" and (ctx.all_attributes | length) > (ctx.attributes | length) %} +{%- for attribute in ctx.all_attributes | sort(attribute="name") %} + {%- if attribute is stable %} + defdelegate {{ c.func_name(attribute.name) }}(), to: {{ stable_module_namespace }}.{{ module_name }} + {% endif -%} +{% endfor %} +{% endif -%} {%- for attribute in ctx.attributes | sort(attribute="name") %} {% if attribute.type is mapping %} @typedoc """ diff --git a/apps/opentelemetry_semantic_conventions/templates/registry/elixir/weaver.yaml b/apps/opentelemetry_semantic_conventions/templates/registry/elixir/weaver.yaml index bd590aea..f845f370 100644 --- a/apps/opentelemetry_semantic_conventions/templates/registry/elixir/weaver.yaml +++ b/apps/opentelemetry_semantic_conventions/templates/registry/elixir/weaver.yaml @@ -15,6 +15,7 @@ templates: | map({ id: .[0].group_id, attributes: [.[].attributes[] | select(.stability == $stability) | (select( .name as $id | any( $excluded_attrs[]; . == $id ) | not ))] | sort_by(.id), + all_attributes: [.[].attributes[]] | sort_by(.id), output: $output + "/attributes/" }) | map(select( .id as $id | any( $excluded[]; . == $id) | not )) diff --git a/apps/opentelemetry_semantic_conventions/templates/registry/erlang/semantic_attributes.hrl.j2 b/apps/opentelemetry_semantic_conventions/templates/registry/erlang/semantic_attributes.hrl.j2 index 4938ed29..a6ac17f8 100644 --- a/apps/opentelemetry_semantic_conventions/templates/registry/erlang/semantic_attributes.hrl.j2 +++ b/apps/opentelemetry_semantic_conventions/templates/registry/erlang/semantic_attributes.hrl.j2 @@ -15,7 +15,9 @@ %% See the License for the specific language governing permissions and %% limitations under the License. %%%------------------------------------------------------------------------- - +{%- if params.stability == "experimental" and (ctx.all_attributes | length) > (ctx.attributes | length) %} +-include("attributes/{{ c.file_name(ctx.id) }}_attributes.hrl"). +{% endif -%} {%- for attribute in ctx.attributes | sort(attribute="name") %} {% if attribute is deprecated -%} %% @deprecated {{ attribute.deprecated | replace("\n", "\n%% ") }} diff --git a/apps/opentelemetry_semantic_conventions/templates/registry/erlang/weaver.yaml b/apps/opentelemetry_semantic_conventions/templates/registry/erlang/weaver.yaml index b7879d8a..28c90ebb 100644 --- a/apps/opentelemetry_semantic_conventions/templates/registry/erlang/weaver.yaml +++ b/apps/opentelemetry_semantic_conventions/templates/registry/erlang/weaver.yaml @@ -15,6 +15,7 @@ templates: | map({ id: .[0].group_id, attributes: [.[].attributes[] | select(.stability == $stability) | (select( .name as $id | any( $excluded_attrs[]; . == $id ) | not ))] | sort_by(.id), + all_attributes: [.[].attributes[]], output: $output + "/attributes/" }) | map(select( .id as $id | any( $excluded[]; . == $id) | not )) diff --git a/apps/opentelemetry_semantic_conventions/test/open_telemetry/semantic_conventions/sem_conv_test.exs b/apps/opentelemetry_semantic_conventions/test/open_telemetry/semantic_conventions/sem_conv_test.exs index 37aeb97e..a8885fbd 100644 --- a/apps/opentelemetry_semantic_conventions/test/open_telemetry/semantic_conventions/sem_conv_test.exs +++ b/apps/opentelemetry_semantic_conventions/test/open_telemetry/semantic_conventions/sem_conv_test.exs @@ -26,4 +26,9 @@ defmodule OpenTelemetry.SemConvTest do System.delete_env("OTEL_SEMCONV_STABILITY_OPT_IN") end end + + test "stable attrs are delegated in incubating module" do + assert SemConv.Incubating.HTTPAttributes.http_route() == + SemConv.HTTPAttributes.http_route() + end end diff --git a/apps/opentelemetry_semantic_conventions/test/opentelemetry_semconv_SUITE.erl b/apps/opentelemetry_semantic_conventions/test/opentelemetry_semconv_SUITE.erl index 7dfd372c..fea72e1e 100644 --- a/apps/opentelemetry_semantic_conventions/test/opentelemetry_semconv_SUITE.erl +++ b/apps/opentelemetry_semantic_conventions/test/opentelemetry_semconv_SUITE.erl @@ -6,6 +6,7 @@ -include_lib("common_test/include/ct.hrl"). -include("incubating/attributes/db_attributes.hrl"). +-include("incubating/attributes/http_attributes.hrl"). all() -> [registry_macros]. @@ -13,4 +14,5 @@ all() -> registry_macros(_Config) -> ?assertEqual('db.system', ?'DB_SYSTEM'), ?assertEqual('postgresql', ?'DB_SYSTEM_VALUES_POSTGRESQL'), + ?assertEqual('http.route', ?'HTTP_ROUTE'), ok.