-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[telemetry] Centralize (as much as is practical) the creation of span…
…s to ease upgrades (#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.
- Loading branch information
1 parent
d0d1fca
commit 82c42a2
Showing
130 changed files
with
1,273 additions
and
2,865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { getTracer, OperationTracingOptions } from "@azure/core-tracing"; | ||
import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; | ||
import { OperationOptions } from "@azure/core-http"; | ||
import { createSpanFunction } from "@azure/core-tracing"; | ||
|
||
/** | ||
* Creates a span using the global tracer. | ||
* @internal | ||
* @param name - The name of the operation being performed. | ||
* @param tracingOptions - The options for the underlying http request. | ||
*/ | ||
export function createSpan<T extends OperationOptions>( | ||
operationName: string, | ||
operationOptions: T | ||
): { span: Span; updatedOptions: T } { | ||
const tracer = getTracer(); | ||
const tracingOptions = operationOptions.tracingOptions || {}; | ||
const spanOptions: SpanOptions = { | ||
...tracingOptions.spanOptions, | ||
kind: SpanKind.INTERNAL | ||
}; | ||
|
||
const span = tracer.startSpan( | ||
`Azure.CognitiveServices.AnomalyDetector.${operationName}`, | ||
spanOptions | ||
); | ||
|
||
span.setAttribute("az.namespace", "Microsoft.CognitiveServices"); | ||
|
||
let newSpanOptions = tracingOptions.spanOptions || {}; | ||
if (span.isRecording()) { | ||
newSpanOptions = { | ||
...tracingOptions.spanOptions, | ||
parent: span.context(), | ||
attributes: { | ||
...spanOptions.attributes, | ||
"az.namespace": "Microsoft.CognitiveServices" | ||
} | ||
}; | ||
} | ||
|
||
const newTracingOptions: OperationTracingOptions = { | ||
...tracingOptions, | ||
spanOptions: newSpanOptions | ||
}; | ||
|
||
const newOperationOptions: T = { | ||
...operationOptions, | ||
tracingOptions: newTracingOptions | ||
}; | ||
|
||
return { | ||
span, | ||
updatedOptions: newOperationOptions | ||
}; | ||
} | ||
export const createSpan = createSpanFunction({ | ||
packagePrefix: "Azure.CognitiveServices.AnomalyDetector", | ||
namespace: "Microsoft.CognitiveServices" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 5 additions & 49 deletions
54
sdk/communication/communication-administration/src/common/tracing.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { OperationOptions } from "@azure/core-http"; | ||
import { getTracer } from "@azure/core-tracing"; | ||
import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; | ||
|
||
type OperationTracingOptions = OperationOptions["tracingOptions"]; | ||
import { createSpanFunction } from "@azure/core-tracing"; | ||
|
||
/** | ||
* Creates a span using the global tracer. | ||
* @internal | ||
* @param name - The name of the operation being performed. | ||
* @param tracingOptions - The options for the underlying http request. | ||
*/ | ||
export function createSpan<T extends OperationOptions>( | ||
operationName: string, | ||
operationOptions: T | ||
): { span: Span; updatedOptions: T } { | ||
const tracer = getTracer(); | ||
const tracingOptions = operationOptions.tracingOptions || {}; | ||
const spanOptions: SpanOptions = { | ||
...tracingOptions.spanOptions, | ||
kind: SpanKind.INTERNAL | ||
}; | ||
|
||
const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions); | ||
|
||
span.setAttribute("az.namespace", "Microsoft.Communication"); | ||
|
||
let newSpanOptions = tracingOptions.spanOptions || {}; | ||
if (span.isRecording()) { | ||
newSpanOptions = { | ||
...tracingOptions.spanOptions, | ||
parent: span.context(), | ||
attributes: { | ||
...spanOptions.attributes, | ||
"az.namespace": "Microsoft.Communication" | ||
} | ||
}; | ||
} | ||
|
||
const newTracingOptions: OperationTracingOptions = { | ||
...tracingOptions, | ||
spanOptions: newSpanOptions | ||
}; | ||
|
||
const newOperationOptions: T = { | ||
...operationOptions, | ||
tracingOptions: newTracingOptions | ||
}; | ||
|
||
return { | ||
span, | ||
updatedOptions: newOperationOptions | ||
}; | ||
} | ||
export const createSpan = createSpanFunction({ | ||
packagePrefix: "Azure.Communication", | ||
namespace: "Microsoft.Communication" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { getTracer } from "@azure/core-tracing"; | ||
import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; | ||
import { OperationOptions } from "@azure/core-http"; | ||
|
||
type OperationTracingOptions = OperationOptions["tracingOptions"]; | ||
import { createSpanFunction } from "@azure/core-tracing"; | ||
|
||
/** | ||
* Creates a span using the global tracer. | ||
* @internal | ||
* @param name - The name of the operation being performed. | ||
* @param tracingOptions - The options for the underlying http request. | ||
*/ | ||
export function createSpan<T extends OperationOptions>( | ||
operationName: string, | ||
operationOptions: T | ||
): { span: Span; updatedOptions: T } { | ||
const tracer = getTracer(); | ||
const tracingOptions = operationOptions.tracingOptions || {}; | ||
const spanOptions: SpanOptions = { | ||
...tracingOptions.spanOptions, | ||
kind: SpanKind.INTERNAL | ||
}; | ||
|
||
const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions); | ||
|
||
span.setAttribute("az.namespace", "Microsoft.Communication"); | ||
|
||
let newSpanOptions = tracingOptions.spanOptions || {}; | ||
if (span.isRecording()) { | ||
newSpanOptions = { | ||
...tracingOptions.spanOptions, | ||
parent: span.context(), | ||
attributes: { | ||
...spanOptions.attributes, | ||
"az.namespace": "Microsoft.Communication" | ||
} | ||
}; | ||
} | ||
|
||
const newTracingOptions: OperationTracingOptions = { | ||
...tracingOptions, | ||
spanOptions: newSpanOptions | ||
}; | ||
|
||
const newOperationOptions: T = { | ||
...operationOptions, | ||
tracingOptions: newTracingOptions | ||
}; | ||
|
||
return { | ||
span, | ||
updatedOptions: newOperationOptions | ||
}; | ||
} | ||
export const createSpan = createSpanFunction({ | ||
packagePrefix: "Azure.Communication", | ||
namespace: "Microsoft.Communication" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 5 additions & 49 deletions
54
sdk/communication/communication-identity/src/common/tracing.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { OperationOptions } from "@azure/core-http"; | ||
import { getTracer } from "@azure/core-tracing"; | ||
import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; | ||
|
||
type OperationTracingOptions = OperationOptions["tracingOptions"]; | ||
import { createSpanFunction } from "@azure/core-tracing"; | ||
|
||
/** | ||
* Creates a span using the global tracer. | ||
* @internal | ||
* @param name - The name of the operation being performed. | ||
* @param tracingOptions - The options for the underlying http request. | ||
*/ | ||
export function createSpan<T extends OperationOptions>( | ||
operationName: string, | ||
operationOptions: T | ||
): { span: Span; updatedOptions: T } { | ||
const tracer = getTracer(); | ||
const tracingOptions = operationOptions.tracingOptions || {}; | ||
const spanOptions: SpanOptions = { | ||
...tracingOptions.spanOptions, | ||
kind: SpanKind.INTERNAL | ||
}; | ||
|
||
const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions); | ||
|
||
span.setAttribute("az.namespace", "Microsoft.Communication"); | ||
|
||
let newSpanOptions = tracingOptions.spanOptions || {}; | ||
if (span.isRecording()) { | ||
newSpanOptions = { | ||
...tracingOptions.spanOptions, | ||
parent: span.context(), | ||
attributes: { | ||
...spanOptions.attributes, | ||
"az.namespace": "Microsoft.Communication" | ||
} | ||
}; | ||
} | ||
|
||
const newTracingOptions: OperationTracingOptions = { | ||
...tracingOptions, | ||
spanOptions: newSpanOptions | ||
}; | ||
|
||
const newOperationOptions: T = { | ||
...operationOptions, | ||
tracingOptions: newTracingOptions | ||
}; | ||
|
||
return { | ||
span, | ||
updatedOptions: newOperationOptions | ||
}; | ||
} | ||
export const createSpan = createSpanFunction({ | ||
packagePrefix: "Azure.Communication", | ||
namespace: "Microsoft.Communication" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { OperationOptions } from "@azure/core-http"; | ||
import { getTracer } from "@azure/core-tracing"; | ||
import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; | ||
|
||
type OperationTracingOptions = OperationOptions["tracingOptions"]; | ||
import { createSpanFunction } from "@azure/core-tracing"; | ||
|
||
/** | ||
* Creates a span using the global tracer. | ||
* @internal | ||
* @param name - The name of the operation being performed. | ||
* @param tracingOptions - The options for the underlying http request. | ||
*/ | ||
export function createSpan<T extends OperationOptions>( | ||
operationName: string, | ||
operationOptions: T | ||
): { span: Span; updatedOptions: T } { | ||
const tracer = getTracer(); | ||
const tracingOptions = operationOptions.tracingOptions || {}; | ||
const spanOptions: SpanOptions = { | ||
...tracingOptions.spanOptions, | ||
kind: SpanKind.INTERNAL | ||
}; | ||
|
||
const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions); | ||
|
||
span.setAttribute("az.namespace", "Microsoft.Communication"); | ||
|
||
let newSpanOptions = tracingOptions.spanOptions || {}; | ||
if (span.isRecording()) { | ||
newSpanOptions = { | ||
...tracingOptions.spanOptions, | ||
parent: span.context(), | ||
attributes: { | ||
...spanOptions.attributes, | ||
"az.namespace": "Microsoft.Communication" | ||
} | ||
}; | ||
} | ||
|
||
const newTracingOptions: OperationTracingOptions = { | ||
...tracingOptions, | ||
spanOptions: newSpanOptions | ||
}; | ||
|
||
const newOperationOptions: T = { | ||
...operationOptions, | ||
tracingOptions: newTracingOptions | ||
}; | ||
|
||
return { | ||
span, | ||
updatedOptions: newOperationOptions | ||
}; | ||
} | ||
export const createSpan = createSpanFunction({ | ||
packagePrefix: "Azure.Communication", | ||
namespace: "Microsoft.Communication" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.