open-telemetry / opentelemetry-js

OpenTelemetry JavaScript Client
https://opentelemetry.io
Apache License 2.0
2.66k stars 767 forks source link

Replace usages of `SpanAttributes`/`MetricAttributes` with `Attributes` #4175

Open pichlermarc opened 11 months ago

pichlermarc commented 11 months ago

SpanAttributes is deprecated, but bumping the minimum API version would be considered breaking. For 2.0 we could replace SpanAttributes with Attributes and bump the minimum API version accordingly.

We can do the same with MetricAttributes


THIS IS A BREAKING CHANGE. PLEASE MAKE PR TO THE next BRANCH FOR INCLUSION IN THE 2.0 RELEASE

Below is a list of files with instances of SpanAttributes or MetricAttributes. In each package, the minimum API version should be bumped to 1.1.0 (first version with the common definition of Attributes) and any instances of SpanAttributes or MetricAttributes should be replaced with Attributes.

Please limit PRs to a single package in order to make them quickly and easily reviewable. If you are working on one of the below packages, please comment so others know the issue is being worked on.

experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts
experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts
experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts
experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts
experimental/packages/opentelemetry-instrumentation-grpc/src/types.ts
experimental/packages/opentelemetry-instrumentation-grpc/test/grpc-protobuf-ts.test.ts
experimental/packages/opentelemetry-instrumentation-grpc/test/helper.ts
experimental/packages/opentelemetry-instrumentation-http/src/http.ts
experimental/packages/opentelemetry-instrumentation-http/src/types.ts
experimental/packages/opentelemetry-instrumentation-http/src/utils.ts
experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts
experimental/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts
experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts
packages/opentelemetry-core/src/common/attributes.ts
packages/opentelemetry-core/src/trace/sampler/ParentBasedSampler.ts
packages/opentelemetry-resources/src/Resource.ts
packages/opentelemetry-resources/src/types.ts
packages/opentelemetry-sdk-trace-base/src/export/ReadableSpan.ts
packages/opentelemetry-sdk-trace-base/src/Sampler.ts
packages/opentelemetry-sdk-trace-base/src/sampler/ParentBasedSampler.ts
packages/opentelemetry-sdk-trace-base/src/Span.ts
packages/opentelemetry-sdk-trace-base/src/TimedEvent.ts
packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts
packages/opentelemetry-sdk-trace-base/test/common/Tracer.test.ts
packages/opentelemetry-semantic-conventions/src/resource/SemanticResourceAttributes.ts
packages/opentelemetry-shim-opentracing/src/shim.ts
packages/sdk-metrics/src/aggregator/types.ts
packages/sdk-metrics/src/exemplar/AlignedHistogramBucketExemplarReservoir.ts
packages/sdk-metrics/src/exemplar/AlwaysSampleExemplarFilter.ts
packages/sdk-metrics/src/exemplar/Exemplar.ts
packages/sdk-metrics/src/exemplar/ExemplarFilter.ts
packages/sdk-metrics/src/exemplar/ExemplarReservoir.ts
packages/sdk-metrics/src/exemplar/NeverSampleExemplarFilter.ts
packages/sdk-metrics/src/exemplar/SimpleFixedSizeExemplarReservoir.ts
packages/sdk-metrics/src/exemplar/WithTraceExemplarFilter.ts
packages/sdk-metrics/src/export/MetricData.ts
packages/sdk-metrics/src/Instruments.ts
packages/sdk-metrics/src/ObservableResult.ts
packages/sdk-metrics/src/state/DeltaMetricProcessor.ts
packages/sdk-metrics/src/state/HashMap.ts
packages/sdk-metrics/src/state/MultiWritableMetricStorage.ts
packages/sdk-metrics/src/state/SyncMetricStorage.ts
packages/sdk-metrics/src/state/WritableMetricStorage.ts
packages/sdk-metrics/src/utils.ts
packages/sdk-metrics/src/view/AttributesProcessor.ts
packages/sdk-metrics/test/MeterProvider.test.ts
packages/sdk-metrics/test/state/HashMap.test.ts
packages/sdk-metrics/test/state/MultiWritableMetricStorage.test.ts
packages/sdk-metrics/test/util.ts
packages/sdk-metrics/test/utils.test.ts
lilacyl commented 10 months ago

I'll work on this. Working on experimental/packages/opentelemetry-exporter-prometheus/

JamieDanielson commented 8 months ago

maybe we make this into a checklist so it's easier to track?

opentelemetry-exporter-prometheus

opentelemetry-instrumentation-fetch

opentelemetry-instrumentation-grpc

opentelemetry-instrumentation-http

opentelemetry-instrumentation-xml-http-request

opentelemetry-core (#4408)

opentelemetry-resources (#4428)

sdk-trace-base

opentelemetry-semantic-conventions (https://github.com/open-telemetry/opentelemetry-js/issues/4175#issuecomment-1899295180)

opentelemetry-shim-opentracing (#4430)

sdk-metrics

JamieDanielson commented 8 months ago

packages/opentelemetry-semantic-conventions/src/resource/SemanticResourceAttributes.ts this is an auto-generated file and the references to SpanAttributes are auto-generated from a script. No changes should be made here.

legendecas commented 8 months ago

I believe ResourceAttributes can be replaced with Attributes as well.

Refs: https://github.com/open-telemetry/opentelemetry-js/pull/4428#discussion_r1458498771

github-actions[bot] commented 5 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

JamieDanielson commented 4 days ago

Adding Marc's comment here because it was a really useful explanation:

We're just allowed to bump the API version for all packages except for ./packages, as these are all stable and that's the only place where it's actually breaking and requires us to bump to 2.0. So what you could actually do is bump all versions in

What we cannot do on main is bump the peer-dependency of any package in ./packages (with one exception, see below) because it's breaking AND the packages are 1.x (semver stable) already. So a user with an older version of @opentelemetry/api installed will get an npm error and won't be able to typescript compile anymore once we exchange SpanAttributes with Attributes as the type does not exist on their version of the API.

However, there are a few packages where we can actually exchange the SpanAttributes and MetricAttributes for Attributes on main even if the package is 1.x (semver stable) already, and that's in all packages where we use @opentelemetry/api@>=1.3.0 already, because:

Everything else that does not fit these constraints must be done in the next branch as they'll actually be breaking for a stable package. :sweat_smile:

So, to summarize, we can bump and replace SpanAttributes and MetricAttributes on main everywhere except for:

These changes would have to go into the next branch and will be released with 2.0.

There is a special case with @opentelemetry/sdk-metrics which is 1.x but it's already depending on API >=1.3.0, so the Attributes type is available. Since that type is available (and there's not difference between Attributes and MetricAttributes) we can just replace all usages of MetricAttributes to Attributes in @opentelemetry/sdk-metrics without any repercussions. :slightly_smiling_face: