Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add semconv generator for semantic-conventions-package #2083

Merged
merged 17 commits into from
Apr 10, 2021

Conversation

weyert
Copy link
Contributor

@weyert weyert commented Apr 8, 2021

Which problem is this PR solving?

Adds a build script which generate the files for the semantic-conventions-package
so it always in sync with the definitions in the specifications-repo

A few unspecified attributes are added manually to the semconv template to
allow existing code to pass, these are:

  // HTTP
  HTTP_ERROR_NAME: 'http.error_name',
  HTTP_ERROR_MESSAGE: 'http.error_message',
  HTTP_STATUS_TEXT: 'http.status_text',

  // GRPC
  GRPC_KIND: 'grpc.kind', // SERVER or CLIENT
  GRPC_METHOD: 'grpc.method',
  GRPC_STATUS_CODE: 'grpc.status_code',
  GRPC_ERROR_NAME: 'grpc.error_name',
  GRPC_ERROR_MESSAGE: 'grpc.error_message',

Fixes #2064

Short description of the changes

This change introduces a script generate.sh in the directory scripts/semconv which allows you to generate the constants which are defined in the semantic conventions section of the Opentelemetry specification.

The following to files are generated:

  • SemanticAttribute
  • ResourceAttribute

All the packages that depend on the @opentelemetry/semantic-conventions-package has been updated to accommodate this change.

To allow this version of the spec files to work with the semconv the
version of this tool had to be lowered to 0.2.1 as there is a breaking
change in 0.3.0 which removes support for the number-type and
because the latest published version of the otel spec is v1.1.0 which
still uses this number-type.

Adds a build script which generate the files for the `semenatic-conventions`-package
so it always in sync with the definitions in the `specifications`-repo

A few unspecified attributes are added manually to the semconv template to
allow existing code to pass, these are:

  // HTTP
  HTTP_ERROR_NAME: 'http.error_name',
  HTTP_ERROR_MESSAGE: 'http.error_message',
  HTTP_STATUS_TEXT: 'http.status_text',

  // GRPC
  GRPC_KIND: 'grpc.kind', // SERVER or CLIENT
  GRPC_METHOD: 'grpc.method',
  GRPC_STATUS_CODE: 'grpc.status_code',
  GRPC_ERROR_NAME: 'grpc.error_name',
  GRPC_ERROR_MESSAGE: 'grpc.error_message',
Updates the different packages to fix the breaking change were there is
only `SemanticAttribute` and `ResourceAttribute`-class defined in the
`@opentelemetry/semantic-conventations`-package
@codecov
Copy link

codecov bot commented Apr 8, 2021

Codecov Report

Merging #2083 (a5dc4fc) into main (7f7afa7) will increase coverage by 0.05%.
The diff coverage is 98.48%.

❗ Current head a5dc4fc differs from pull request most recent head 628bb71. Consider uploading reports for the commit 628bb71 to get more accurate results

@@            Coverage Diff             @@
##             main    #2083      +/-   ##
==========================================
+ Coverage   92.53%   92.59%   +0.05%     
==========================================
  Files         133      137       +4     
  Lines        4851     4872      +21     
  Branches     1002     1005       +3     
==========================================
+ Hits         4489     4511      +22     
+ Misses        362      361       -1     
Impacted Files Coverage Δ
packages/opentelemetry-tracing/src/enums.ts 100.00% <ø> (ø)
...es/opentelemetry-instrumentation-http/src/utils.ts 99.04% <94.44%> (+<0.01%) ⬆️
...-instrumentation-fetch/src/enums/AttributeNames.ts 100.00% <100.00%> (ø)
...s/opentelemetry-instrumentation-fetch/src/fetch.ts 99.27% <100.00%> (ø)
...es/opentelemetry-instrumentation-grpc/src/enums.ts 100.00% <100.00%> (ø)
...ry-instrumentation-grpc/src/grpc-js/clientUtils.ts 92.59% <100.00%> (+0.09%) ⬆️
...elemetry-instrumentation-grpc/src/grpc-js/index.ts 90.81% <100.00%> (ø)
...ry-instrumentation-grpc/src/grpc-js/serverUtils.ts 91.66% <100.00%> (+0.11%) ⬆️
...metry-instrumentation-grpc/src/grpc/clientUtils.ts 88.40% <100.00%> (+0.17%) ⬆️
...entelemetry-instrumentation-grpc/src/grpc/index.ts 93.04% <100.00%> (ø)
... and 11 more

Changed `generate.sh` to ensure it generates the files against the latest
published version of the otel specification which is v1.1.0.

To allow this version of the spec files to work with the `semconv` the
version of this tool had to be lowered to 0.2.1 as there is a breaking
change in 0.3.0 which removes support for the `number`-type.

{%- if class == "SemanticAttribute" %}

// Manually defined and not YET in the YAML
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there plan to add them upstream ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I am not sure. Might be worth considering. I have added them to avoid needing to change too much code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these sound like obsolete attributes that are represented/named differently

  • grpc.kind should be represented as the Span Kind
  • grpc.status_code should be rpc.grpc.status_code
  • grpc.error_name is redundant with the code
  • gprc.status_message is probably worth filing a spec PR for (as rpc.grpc.status_message). The span status message might not be ideal to use for it, for the same reason we don't mark spans as failed in RecordException.
  • http.status_text was deemed useless and removed without replacement, see Remove semantic convention for http.status_text opentelemetry-specification#950.
  • http.error_name, http.status_text: No idea what these are.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they shouldn't be defined here anyway if they aren't in the semantic conventions. Anything in this package should be only things approved by spec and by including them we are giving them our implicit approval for third parties. Most people will assume anything they find in autocomplete here is "official"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved them into the packages and updated the code accordingly
Also made sure that we use rpc.grpc.status_code instead of the previous one

@weyert
Copy link
Contributor Author

weyert commented Apr 8, 2021

I have to make some more changes related to this ticket: open-telemetry/build-tools#41

But looking forward hearing if this approach is fine. Having a second look I am not sure if we want to name it ResourceAttributes and SemanticAttributes (plural)

@dyladan
Copy link
Member

dyladan commented Apr 8, 2021

I have to make some more changes related to this ticket: open-telemetry/build-tools#41

But looking forward hearing if this approach is fine. Having a second look I am not sure if we want to name it ResourceAttributes and SemanticAttributes (plural)

I would for sure prefer ResourceAttributes and SpanAttributes. Technically they are all semantic attributes so that name doesn't really add much.

- Removed all the semantic convention constants from the
`@opentelemetry/semantic-conventions`-package that are not part of the
Opentelemetry Specification v1.1.0
- Renamed the `ResourceAttribute`-class to `ResourceAttributes`
- Renamed the `SemanticAttribute`-class to `SemanticAttributes`
   as `SpanAttributes` name conflicts with the interface defined
   in the `api`-package
- Updated references in the packages to use the new names
@weyert
Copy link
Contributor Author

weyert commented Apr 8, 2021

I have to make some more changes related to this ticket: open-telemetry/build-tools#41
But looking forward hearing if this approach is fine. Having a second look I am not sure if we want to name it ResourceAttributes and SemanticAttributes (plural)

I would for sure prefer ResourceAttributes and SpanAttributes. Technically they are all semantic attributes so that name doesn't really add much.

I have renamed ResourceAttributes but for now using SemanticAttributes mainly because we already have SpanAttributes in the api-package which I think could cause confusion. But I am happy make the name change to SpanAttributes if the potential conflict/confusion is of no concern.

…ator

# Conflicts:
#	packages/opentelemetry-plugin-grpc-js/src/client/utils.ts
#	packages/opentelemetry-plugin-grpc-js/src/server/clientStreamAndUnary.ts
#	packages/opentelemetry-plugin-grpc-js/src/server/patchServer.ts
#	packages/opentelemetry-plugin-grpc-js/src/server/serverStreamAndBidi.ts
#	packages/opentelemetry-plugin-grpc/src/grpc.ts
#	packages/opentelemetry-plugin-http/src/utils.ts
#	packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts
#	packages/opentelemetry-plugin-http/test/functionals/utils.test.ts
#	packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts
#	packages/opentelemetry-plugin-http/test/utils/assertSpan.ts
#	packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts
#	packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts
#	packages/opentelemetry-plugin-https/test/utils/assertSpan.ts
Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is wrong during merging with main branch you have restored all the removed plugins

@weyert
Copy link
Contributor Author

weyert commented Apr 9, 2021

Something is wrong during merging with main branch you have restored all the removed plugins

Yes, sorry about that, I noticed that too. Think it's resolved now. Sourcetree is confusing with displaying deleted files when you have changes to the same files

Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works like a charm, one small suggestion

scripts/semconv/generate.sh Outdated Show resolved Hide resolved
@vmarchaud vmarchaud merged commit 031b0f4 into open-telemetry:main Apr 10, 2021
@weyert
Copy link
Contributor Author

weyert commented Apr 10, 2021

Thank you for approving :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autogenerate semantic convention constants
7 participants