Skip to content

Commit 82c42a2

Browse files
[telemetry] Centralize (as much as is practical) the creation of spans to ease upgrades (Azure#13887)
As part of prepping for the next release of OpenTelemetry we found some code patterns that were going to become a large maintenance burden for us, primarily around the parenting of spans. To make this easier I've removed as many duplicate implementation of createSpan and tried to centralize everything into core-tracing instead. This won't completely remove changes needed for a newer version of OpenTelemetry but it'll eliminate one of the bigger bottlenecks.
1 parent d0d1fca commit 82c42a2

File tree

130 files changed

+1273
-2865
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+1273
-2865
lines changed

sdk/anomalydetector/ai-anomaly-detector/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"@azure/logger": "^1.0.0",
6868
"@opentelemetry/api": "^0.10.2",
6969
"tslib": "^2.0.0",
70-
"@azure/core-tracing": "1.0.0-preview.9"
70+
"@azure/core-tracing": "1.0.0-beta.1"
7171
},
7272
"devDependencies": {
7373
"@azure/dev-tool": "^1.0.0",
Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,13 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import { getTracer, OperationTracingOptions } from "@azure/core-tracing";
5-
import { Span, SpanOptions, SpanKind } from "@opentelemetry/api";
6-
import { OperationOptions } from "@azure/core-http";
4+
import { createSpanFunction } from "@azure/core-tracing";
75

86
/**
97
* Creates a span using the global tracer.
108
* @internal
11-
* @param name - The name of the operation being performed.
12-
* @param tracingOptions - The options for the underlying http request.
139
*/
14-
export function createSpan<T extends OperationOptions>(
15-
operationName: string,
16-
operationOptions: T
17-
): { span: Span; updatedOptions: T } {
18-
const tracer = getTracer();
19-
const tracingOptions = operationOptions.tracingOptions || {};
20-
const spanOptions: SpanOptions = {
21-
...tracingOptions.spanOptions,
22-
kind: SpanKind.INTERNAL
23-
};
24-
25-
const span = tracer.startSpan(
26-
`Azure.CognitiveServices.AnomalyDetector.${operationName}`,
27-
spanOptions
28-
);
29-
30-
span.setAttribute("az.namespace", "Microsoft.CognitiveServices");
31-
32-
let newSpanOptions = tracingOptions.spanOptions || {};
33-
if (span.isRecording()) {
34-
newSpanOptions = {
35-
...tracingOptions.spanOptions,
36-
parent: span.context(),
37-
attributes: {
38-
...spanOptions.attributes,
39-
"az.namespace": "Microsoft.CognitiveServices"
40-
}
41-
};
42-
}
43-
44-
const newTracingOptions: OperationTracingOptions = {
45-
...tracingOptions,
46-
spanOptions: newSpanOptions
47-
};
48-
49-
const newOperationOptions: T = {
50-
...operationOptions,
51-
tracingOptions: newTracingOptions
52-
};
53-
54-
return {
55-
span,
56-
updatedOptions: newOperationOptions
57-
};
58-
}
10+
export const createSpan = createSpanFunction({
11+
packagePrefix: "Azure.CognitiveServices.AnomalyDetector",
12+
namespace: "Microsoft.CognitiveServices"
13+
});

sdk/appconfiguration/app-configuration/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"@azure/core-asynciterator-polyfill": "^1.0.0",
9090
"@azure/core-http": "^1.2.0",
9191
"@azure/core-paging": "^1.1.1",
92-
"@azure/core-tracing": "1.0.0-preview.9",
92+
"@azure/core-tracing": "1.0.0-beta.1",
9393
"@opentelemetry/api": "^0.10.2",
9494
"tslib": "^2.0.0"
9595
},

sdk/communication/communication-administration/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@azure/core-lro": "^1.0.2",
7474
"@azure/core-paging": "^1.1.1",
7575
"@azure/logger": "^1.0.0",
76-
"@azure/core-tracing": "1.0.0-preview.9",
76+
"@azure/core-tracing": "1.0.0-beta.1",
7777
"@opentelemetry/api": "^0.10.2",
7878
"events": "^3.0.0",
7979
"tslib": "^2.0.0"
Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,13 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import { OperationOptions } from "@azure/core-http";
5-
import { getTracer } from "@azure/core-tracing";
6-
import { Span, SpanOptions, SpanKind } from "@opentelemetry/api";
7-
8-
type OperationTracingOptions = OperationOptions["tracingOptions"];
4+
import { createSpanFunction } from "@azure/core-tracing";
95

106
/**
117
* Creates a span using the global tracer.
128
* @internal
13-
* @param name - The name of the operation being performed.
14-
* @param tracingOptions - The options for the underlying http request.
159
*/
16-
export function createSpan<T extends OperationOptions>(
17-
operationName: string,
18-
operationOptions: T
19-
): { span: Span; updatedOptions: T } {
20-
const tracer = getTracer();
21-
const tracingOptions = operationOptions.tracingOptions || {};
22-
const spanOptions: SpanOptions = {
23-
...tracingOptions.spanOptions,
24-
kind: SpanKind.INTERNAL
25-
};
26-
27-
const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions);
28-
29-
span.setAttribute("az.namespace", "Microsoft.Communication");
30-
31-
let newSpanOptions = tracingOptions.spanOptions || {};
32-
if (span.isRecording()) {
33-
newSpanOptions = {
34-
...tracingOptions.spanOptions,
35-
parent: span.context(),
36-
attributes: {
37-
...spanOptions.attributes,
38-
"az.namespace": "Microsoft.Communication"
39-
}
40-
};
41-
}
42-
43-
const newTracingOptions: OperationTracingOptions = {
44-
...tracingOptions,
45-
spanOptions: newSpanOptions
46-
};
47-
48-
const newOperationOptions: T = {
49-
...operationOptions,
50-
tracingOptions: newTracingOptions
51-
};
52-
53-
return {
54-
span,
55-
updatedOptions: newOperationOptions
56-
};
57-
}
10+
export const createSpan = createSpanFunction({
11+
packagePrefix: "Azure.Communication",
12+
namespace: "Microsoft.Communication"
13+
});

sdk/communication/communication-chat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"@azure/communication-signaling": "1.0.0-beta.2",
7070
"@azure/core-auth": "^1.2.0",
7171
"@azure/core-http": "^1.2.0",
72-
"@azure/core-tracing": "1.0.0-preview.9",
72+
"@azure/core-tracing": "1.0.0-beta.1",
7373
"@azure/logger": "^1.0.0",
7474
"@opentelemetry/api": "^0.10.2",
7575
"events": "^3.0.0",
Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,13 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import { getTracer } from "@azure/core-tracing";
5-
import { Span, SpanOptions, SpanKind } from "@opentelemetry/api";
6-
import { OperationOptions } from "@azure/core-http";
7-
8-
type OperationTracingOptions = OperationOptions["tracingOptions"];
4+
import { createSpanFunction } from "@azure/core-tracing";
95

106
/**
117
* Creates a span using the global tracer.
128
* @internal
13-
* @param name - The name of the operation being performed.
14-
* @param tracingOptions - The options for the underlying http request.
159
*/
16-
export function createSpan<T extends OperationOptions>(
17-
operationName: string,
18-
operationOptions: T
19-
): { span: Span; updatedOptions: T } {
20-
const tracer = getTracer();
21-
const tracingOptions = operationOptions.tracingOptions || {};
22-
const spanOptions: SpanOptions = {
23-
...tracingOptions.spanOptions,
24-
kind: SpanKind.INTERNAL
25-
};
26-
27-
const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions);
28-
29-
span.setAttribute("az.namespace", "Microsoft.Communication");
30-
31-
let newSpanOptions = tracingOptions.spanOptions || {};
32-
if (span.isRecording()) {
33-
newSpanOptions = {
34-
...tracingOptions.spanOptions,
35-
parent: span.context(),
36-
attributes: {
37-
...spanOptions.attributes,
38-
"az.namespace": "Microsoft.Communication"
39-
}
40-
};
41-
}
42-
43-
const newTracingOptions: OperationTracingOptions = {
44-
...tracingOptions,
45-
spanOptions: newSpanOptions
46-
};
47-
48-
const newOperationOptions: T = {
49-
...operationOptions,
50-
tracingOptions: newTracingOptions
51-
};
52-
53-
return {
54-
span,
55-
updatedOptions: newOperationOptions
56-
};
57-
}
10+
export const createSpan = createSpanFunction({
11+
packagePrefix: "Azure.Communication",
12+
namespace: "Microsoft.Communication"
13+
});

sdk/communication/communication-identity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"@azure/core-lro": "^1.0.2",
7373
"@azure/core-paging": "^1.1.1",
7474
"@azure/logger": "^1.0.0",
75-
"@azure/core-tracing": "1.0.0-preview.9",
75+
"@azure/core-tracing": "1.0.0-beta.1",
7676
"@opentelemetry/api": "^0.10.2",
7777
"events": "^3.0.0",
7878
"tslib": "^2.0.0"
Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,13 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import { OperationOptions } from "@azure/core-http";
5-
import { getTracer } from "@azure/core-tracing";
6-
import { Span, SpanOptions, SpanKind } from "@opentelemetry/api";
7-
8-
type OperationTracingOptions = OperationOptions["tracingOptions"];
4+
import { createSpanFunction } from "@azure/core-tracing";
95

106
/**
117
* Creates a span using the global tracer.
128
* @internal
13-
* @param name - The name of the operation being performed.
14-
* @param tracingOptions - The options for the underlying http request.
159
*/
16-
export function createSpan<T extends OperationOptions>(
17-
operationName: string,
18-
operationOptions: T
19-
): { span: Span; updatedOptions: T } {
20-
const tracer = getTracer();
21-
const tracingOptions = operationOptions.tracingOptions || {};
22-
const spanOptions: SpanOptions = {
23-
...tracingOptions.spanOptions,
24-
kind: SpanKind.INTERNAL
25-
};
26-
27-
const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions);
28-
29-
span.setAttribute("az.namespace", "Microsoft.Communication");
30-
31-
let newSpanOptions = tracingOptions.spanOptions || {};
32-
if (span.isRecording()) {
33-
newSpanOptions = {
34-
...tracingOptions.spanOptions,
35-
parent: span.context(),
36-
attributes: {
37-
...spanOptions.attributes,
38-
"az.namespace": "Microsoft.Communication"
39-
}
40-
};
41-
}
42-
43-
const newTracingOptions: OperationTracingOptions = {
44-
...tracingOptions,
45-
spanOptions: newSpanOptions
46-
};
47-
48-
const newOperationOptions: T = {
49-
...operationOptions,
50-
tracingOptions: newTracingOptions
51-
};
52-
53-
return {
54-
span,
55-
updatedOptions: newOperationOptions
56-
};
57-
}
10+
export const createSpan = createSpanFunction({
11+
packagePrefix: "Azure.Communication",
12+
namespace: "Microsoft.Communication"
13+
});

sdk/communication/communication-sms/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"@azure/communication-common": "1.0.0-beta.6",
7272
"@azure/core-auth": "^1.2.0",
7373
"@azure/core-http": "^1.2.0",
74-
"@azure/core-tracing": "1.0.0-preview.9",
74+
"@azure/core-tracing": "1.0.0-beta.1",
7575
"@azure/logger": "^1.0.0",
7676
"@opentelemetry/api": "^0.10.2",
7777
"events": "^3.0.0",

0 commit comments

Comments
 (0)