Skip to content

Commit cafd67f

Browse files
fengmk2minherzaabmassms-ph
authored
chore(deps)!: upgrade to otel v2.0.0 (#791)
* chore(deps): upgrade to otel v2.0.0 this is a breaking change closes #790 * Update packages/opentelemetry-resource-util/package.json Co-authored-by: Aaron Abbott <[email protected]> * chore(ci): remove Node.js 14 from CI matrix fix(pkg): rename exporter packages to align with ownership feat(node): update required Node.js version to 16 refactor(tracing): remove unused Tracer import and update resource detection method feat(ci): add support for upgrading to OpenTelemetry v2 branch style(tracing): adjust formatting for better readability in configurations feat(ci): modify branch triggers for CI workflow chore(revert) feat(resource): improve resource detection by refactoring to use detectResources * Fix changes that were made to instrument snapshot tests * remove commented lines * remove OT_VERSION from user agent strings since there is no public API to get it Adding it at build time won't work since the peerDependency may be a different version at runtime. Some possible alternatives: - read it defensively from "@opentelemetry/core/build/src/version.ts" even though it's not exported from index and may disappear - try to read it from package.json which may fail with bundling and is clunky * Revert "remove OT_VERSION from user agent strings since there is no public API to get it" This reverts commit ca1b573. * Try to lazily get version from package.json or fallback to "unknown" * Make sure that ATTRIBUTE_NAMES statically contains all possible keys * simplify detector.test.ts * fix instrumentation quickstart * Restore the original dep versions for @opentelemetry/semantic-conventions * remove some unused code BREAKING CHANGE: drops compatibility with OpenTelemetry SDK 1.0 which changes some types and may require some updates. For more information on the changes and migrating to 2.x, see https://github.com/open-telemetry/opentelemetry-js/blob/v2.0.1/doc/upgrade-to-2.x.md. --------- Co-authored-by: LeoY <[email protected]> Co-authored-by: Aaron Abbott <[email protected]> Co-authored-by: ms-ph <[email protected]> Co-authored-by: Aaron Abbott <[email protected]>
1 parent 86e4edf commit cafd67f

File tree

37 files changed

+13273
-11703
lines changed

37 files changed

+13273
-11703
lines changed

e2e-test-server/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
"@google-cloud/opentelemetry-resource-util": "^2.0.0",
4040
"@google-cloud/pubsub": "^4.0.0",
4141
"@grpc/grpc-js": "^1.3.2",
42-
"@opentelemetry/api": "^1.0.0",
43-
"@opentelemetry/context-async-hooks": "^1.0.0",
44-
"@opentelemetry/core": "^1.0.0",
45-
"@opentelemetry/resources": "^1.0.0",
46-
"@opentelemetry/sdk-trace-base": "^1.0.0",
42+
"@opentelemetry/api": "^1.9.0",
43+
"@opentelemetry/context-async-hooks": "^2.0.0",
44+
"@opentelemetry/core": "^2.0.0",
45+
"@opentelemetry/resources": "^2.0.0",
46+
"@opentelemetry/sdk-trace-base": "^2.0.0",
4747
"express": "^4.21.0",
4848
"winston": "^3.3.3"
4949
}

e2e-test-server/src/scenarios.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,23 @@
1414

1515
import {status as Status} from '@grpc/grpc-js';
1616
import {
17-
Tracer,
1817
BasicTracerProvider,
1918
BatchSpanProcessor,
2019
TracerConfig,
2120
} from '@opentelemetry/sdk-trace-base';
2221
import {AlwaysOnSampler} from '@opentelemetry/sdk-trace-base';
2322
import {
24-
Resource,
2523
envDetector,
26-
detectResourcesSync,
24+
detectResources,
25+
emptyResource,
2726
} from '@opentelemetry/resources';
2827
import {
2928
TraceExporter,
3029
TraceExporterOptions,
3130
} from '@google-cloud/opentelemetry-cloud-trace-exporter';
3231
import {GcpDetectorSync} from '@google-cloud/opentelemetry-resource-util';
3332
import * as constants from './constants';
34-
import {context, SpanKind} from '@opentelemetry/api';
33+
import {context, SpanKind, Tracer} from '@opentelemetry/api';
3534
import {AsyncHooksContextManager} from '@opentelemetry/context-async-hooks';
3635

3736
export interface Request {
@@ -55,19 +54,16 @@ async function withTracer<R>(
5554
exporterConfig?: TraceExporterOptions;
5655
} = {}
5756
): Promise<R> {
57+
const exporter = new TraceExporter({
58+
projectId: constants.PROJECT_ID,
59+
...options.exporterConfig,
60+
});
5861
const tracerProvider = new BasicTracerProvider({
5962
sampler: new AlwaysOnSampler(),
60-
resource: Resource.EMPTY,
63+
resource: emptyResource(),
64+
spanProcessors: [new BatchSpanProcessor(exporter)],
6165
...options.tracerConfig,
6266
});
63-
tracerProvider.addSpanProcessor(
64-
new BatchSpanProcessor(
65-
new TraceExporter({
66-
projectId: constants.PROJECT_ID,
67-
...options.exporterConfig,
68-
})
69-
)
70-
);
7167

7268
try {
7369
return f(tracerProvider.getTracer(constants.INSTRUMENTING_MODULE_NAME));
@@ -121,7 +117,11 @@ async function complexTrace(request: Request): Promise<Response> {
121117
}
122118

123119
async function detectResource(request: Request): Promise<Response> {
124-
return await withTracer(
120+
const resource = await detectResources({
121+
detectors: [new GcpDetectorSync(), envDetector],
122+
});
123+
124+
return withTracer(
125125
async (tracer: Tracer): Promise<Response> => {
126126
const span = tracer.startSpan('resourceDetectionTrace', {
127127
attributes: {[constants.TEST_ID]: request.testId},
@@ -131,11 +131,7 @@ async function detectResource(request: Request): Promise<Response> {
131131
return {statusCode: Status.OK, headers: {[constants.TRACE_ID]: traceId}};
132132
},
133133
{
134-
tracerConfig: {
135-
resource: detectResourcesSync({
136-
detectors: [new GcpDetectorSync(), envDetector],
137-
}),
138-
},
134+
tracerConfig: {resource},
139135
exporterConfig: {
140136
// Pass through all resource labels as /detectResource scenario checks for OTel
141137
// semantic convention attributes to be present.

0 commit comments

Comments
 (0)