Skip to content

Commit ea7cfe8

Browse files
committed
wip: upgrade to otel 2.0
1 parent ad8f46e commit ea7cfe8

File tree

9 files changed

+1551
-227
lines changed

9 files changed

+1551
-227
lines changed

js/core/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
"license": "Apache-2.0",
2828
"dependencies": {
2929
"@opentelemetry/api": "^1.9.0",
30-
"@opentelemetry/context-async-hooks": "~1.25.0",
31-
"@opentelemetry/core": "~1.25.0",
32-
"@opentelemetry/sdk-metrics": "~1.25.0",
33-
"@opentelemetry/sdk-node": "^0.52.0",
34-
"@opentelemetry/sdk-trace-base": "~1.25.0",
35-
"@opentelemetry/exporter-jaeger": "^1.25.0",
30+
"@opentelemetry/context-async-hooks": "^2.2.0",
31+
"@opentelemetry/core": "^2.2.0",
32+
"@opentelemetry/sdk-metrics": "^2.2.0",
33+
"@opentelemetry/sdk-node": "^0.208.0",
34+
"@opentelemetry/sdk-trace-base": "^2.2.0",
35+
"@opentelemetry/exporter-jaeger": "^2.2.0",
3636
"@types/json-schema": "^7.0.15",
3737
"ajv": "^8.12.0",
3838
"ajv-formats": "^3.0.1",

js/core/src/tracing/exporter.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class TraceServerExporter implements SpanExporter {
7272
displayName: span.name,
7373
links: span.links,
7474
spanKind: SpanKind[span.kind],
75-
parentSpanId: span.parentSpanId,
75+
parentSpanId: span.parentSpanContext?.spanId,
7676
sameProcessAsParentSpan: { value: !span.spanContext().isRemote },
7777
status: span.status,
7878
timeEvents: {
@@ -85,17 +85,17 @@ export class TraceServerExporter implements SpanExporter {
8585
})),
8686
},
8787
};
88-
if (span.instrumentationLibrary !== undefined) {
89-
spanData.instrumentationLibrary = {
90-
name: span.instrumentationLibrary.name,
88+
if (span.instrumentationScope !== undefined) {
89+
spanData.instrumentationScope = {
90+
name: span.instrumentationScope.name,
9191
};
92-
if (span.instrumentationLibrary.schemaUrl !== undefined) {
93-
spanData.instrumentationLibrary.schemaUrl =
94-
span.instrumentationLibrary.schemaUrl;
92+
if (span.instrumentationScope.schemaUrl !== undefined) {
93+
spanData.instrumentationScope.schemaUrl =
94+
span.instrumentationScope.schemaUrl;
9595
}
96-
if (span.instrumentationLibrary.version !== undefined) {
97-
spanData.instrumentationLibrary.version =
98-
span.instrumentationLibrary.version;
96+
if (span.instrumentationScope.version !== undefined) {
97+
spanData.instrumentationScope.version =
98+
span.instrumentationScope.version;
9999
}
100100
}
101101
deleteUndefinedProps(spanData);

js/core/src/tracing/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const LinkSchema = z.object({
7474
droppedAttributesCount: z.number().optional(),
7575
});
7676

77-
export const InstrumentationLibrarySchema = z.object({
77+
export const InstrumentationScopeSchema = z.object({
7878
name: z.string().readonly(),
7979
version: z.string().optional().readonly(),
8080
schemaUrl: z.string().optional().readonly(),
@@ -89,7 +89,7 @@ export const SpanDataSchema = z.object({
8989
attributes: z.record(z.string(), z.any()),
9090
displayName: z.string(),
9191
links: z.array(LinkSchema).optional(),
92-
instrumentationLibrary: InstrumentationLibrarySchema,
92+
instrumentationScope: InstrumentationScopeSchema,
9393
spanKind: z.string(),
9494
sameProcessAsParentSpan: z.object({ value: z.boolean() }).optional(),
9595
status: SpanStatusSchema.optional(),

js/core/tests/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class TestSpanExporter implements SpanExporter {
4141
displayName: span.name,
4242
links: span.links,
4343
spanKind: SpanKind[span.kind],
44-
parentSpanId: span.parentSpanId,
44+
parentSpanId: span.parentSpanContext?.spanId,
4545
sameProcessAsParentSpan: { value: !span.spanContext().isRemote },
4646
status: span.status,
4747
timeEvents: {

js/plugins/google-cloud/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232
"license": "Apache-2.0",
3333
"dependencies": {
3434
"@google-cloud/logging-winston": "^6.0.0",
35-
"@google-cloud/opentelemetry-cloud-monitoring-exporter": "^0.19.0",
36-
"@google-cloud/opentelemetry-cloud-trace-exporter": "^2.4.1",
37-
"@google-cloud/opentelemetry-resource-util": "^2.4.0",
35+
"@google-cloud/opentelemetry-cloud-monitoring-exporter": "^0.21.0",
36+
"@google-cloud/opentelemetry-cloud-trace-exporter": "^3.0.0",
37+
"@google-cloud/opentelemetry-resource-util": "^3.0.0",
3838
"@opentelemetry/api": "^1.9.0",
39-
"@opentelemetry/auto-instrumentations-node": "^0.49.1",
40-
"@opentelemetry/core": "~1.25.0",
41-
"@opentelemetry/instrumentation": "^0.52.0",
42-
"@opentelemetry/instrumentation-pino": "^0.41.0",
43-
"@opentelemetry/instrumentation-winston": "^0.39.0",
44-
"@opentelemetry/resources": "~1.25.0",
45-
"@opentelemetry/sdk-metrics": "~1.25.0",
46-
"@opentelemetry/sdk-node": "^0.52.0",
47-
"@opentelemetry/sdk-trace-base": "~1.25.0",
39+
"@opentelemetry/auto-instrumentations-node": "^0.67.1",
40+
"@opentelemetry/core": "^2.2.0",
41+
"@opentelemetry/instrumentation": "^0.208.0",
42+
"@opentelemetry/instrumentation-pino": "^0.55.0",
43+
"@opentelemetry/instrumentation-winston": "^0.53.0",
44+
"@opentelemetry/resources": "^2.2.0",
45+
"@opentelemetry/sdk-metrics": "^2.2.0",
46+
"@opentelemetry/sdk-node": "^0.208.0",
47+
"@opentelemetry/sdk-trace-base": "^2.2.0",
4848
"google-auth-library": "^9.6.3",
4949
"node-fetch": "^3.3.2",
5050
"winston": "^3.12.0"

js/plugins/google-cloud/src/gcpOpenTelemetry.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import { type ExportResult } from '@opentelemetry/core';
2626
import type { Instrumentation } from '@opentelemetry/instrumentation';
2727
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
2828
import { WinstonInstrumentation } from '@opentelemetry/instrumentation-winston';
29-
import { Resource } from '@opentelemetry/resources';
29+
import { Resource, resourceFromAttributes } from '@opentelemetry/resources';
3030
import {
31+
AggregationOption,
3132
AggregationTemporality,
32-
DefaultAggregation,
33-
ExponentialHistogramAggregation,
33+
AggregationType,
3434
InMemoryMetricExporter,
3535
InstrumentType,
3636
PeriodicExportingMetricReader,
@@ -73,9 +73,12 @@ export class GcpOpenTelemetry {
7373

7474
constructor(config: GcpTelemetryConfig) {
7575
this.config = config;
76-
this.resource = new Resource({ type: 'global' }).merge(
77-
new GcpDetectorSync().detect()
78-
);
76+
77+
const detectedResource = new GcpDetectorSync().detect();
78+
this.resource = resourceFromAttributes({
79+
type: 'global',
80+
...detectedResource.attributes,
81+
});
7982
}
8083

8184
/**
@@ -237,11 +240,11 @@ class MetricExporterWrapper extends MetricExporter {
237240
});
238241
}
239242

240-
selectAggregation(instrumentType: InstrumentType) {
243+
selectAggregation(instrumentType: InstrumentType): AggregationOption {
241244
if (instrumentType === InstrumentType.HISTOGRAM) {
242-
return new ExponentialHistogramAggregation();
245+
return { type: AggregationType.EXPONENTIAL_HISTOGRAM };
243246
}
244-
return new DefaultAggregation();
247+
return { type: AggregationType.DEFAULT };
245248
}
246249

247250
selectAggregationTemporality(instrumentType: InstrumentType) {

0 commit comments

Comments
 (0)