Skip to content

Commit 3c5b0cb

Browse files
Merge pull request #269362 from hectorhdzg/hectorhdzg/updatespanlog
[Azure Monitor] Update docs to align with latest config in distro
2 parents 64c0067 + 1d2543d commit 3c5b0cb

File tree

2 files changed

+43
-42
lines changed

2 files changed

+43
-42
lines changed

articles/azure-monitor/app/opentelemetry-add-modify.md

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,17 +1725,9 @@ Adding one or more span attributes populates the `customDimensions` field in the
17251725
```typescript
17261726
// Import the necessary packages.
17271727
const { useAzureMonitor } = require("@azure/monitor-opentelemetry");
1728-
const { trace, ProxyTracerProvider } = require("@opentelemetry/api");
17291728
const { ReadableSpan, Span, SpanProcessor } = require("@opentelemetry/sdk-trace-base");
1730-
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
17311729
const { SemanticAttributes } = require("@opentelemetry/semantic-conventions");
17321730

1733-
// Enable Azure Monitor integration.
1734-
useAzureMonitor();
1735-
1736-
// Get the NodeTracerProvider instance.
1737-
const tracerProvider = ((trace.getTracerProvider() as ProxyTracerProvider).getDelegate() as NodeTracerProvider);
1738-
17391731
// Create a new SpanEnrichingProcessor class.
17401732
class SpanEnrichingProcessor implements SpanProcessor {
17411733
forceFlush(): Promise<void> {
@@ -1755,8 +1747,13 @@ class SpanEnrichingProcessor implements SpanProcessor {
17551747
}
17561748
}
17571749

1758-
// Add the SpanEnrichingProcessor instance to the NodeTracerProvider instance.
1759-
tracerProvider.addSpanProcessor(new SpanEnrichingProcessor());
1750+
// Enable Azure Monitor integration.
1751+
const options: AzureMonitorOpenTelemetryOptions = {
1752+
// Add the SpanEnrichingProcessor
1753+
spanProcessors: [new SpanEnrichingProcessor()]
1754+
}
1755+
useAzureMonitor(options);
1756+
17601757
```
17611758

17621759
##### [Python](#tab/python)
@@ -1960,29 +1957,27 @@ Logback, Log4j, and java.util.logging are [autoinstrumented](#logs). Attaching c
19601957
#### [Node.js](#tab/nodejs)
19611958

19621959
```typescript
1963-
// Import the useAzureMonitor function and the logs module from the @azure/monitor-opentelemetry and @opentelemetry/api-logs packages, respectively.
19641960
const { useAzureMonitor } = require("@azure/monitor-opentelemetry");
1965-
const { logs } = require("@opentelemetry/api-logs");
1966-
import { Logger } from "@opentelemetry/sdk-logs";
1961+
const bunyan = require('bunyan');
19671962

1968-
// Enable Azure Monitor integration.
1969-
useAzureMonitor();
1963+
// Instrumentations configuration
1964+
const options: AzureMonitorOpenTelemetryOptions = {
1965+
instrumentationOptions: {
1966+
// Instrumentations generating logs
1967+
bunyan: { enabled: true },
1968+
}
1969+
};
19701970

1971-
// Get the logger for the "testLogger" logger name.
1972-
const logger = (logs.getLogger("testLogger") as Logger);
1971+
// Enable Azure Monitor integration
1972+
useAzureMonitor(options);
19731973

1974-
// Create a new log record.
1975-
const logRecord = {
1976-
body: "testEvent",
1977-
attributes: {
1974+
var log = bunyan.createLogger({ name: 'testApp' });
1975+
log.info({
19781976
"testAttribute1": "testValue1",
19791977
"testAttribute2": "testValue2",
19801978
"testAttribute3": "testValue3"
1981-
}
1982-
};
1979+
}, 'testEvent');
19831980

1984-
// Emit the log record.
1985-
logger.emit(logRecord);
19861981
```
19871982

19881983
#### [Python](#tab/python)
@@ -2147,18 +2142,28 @@ See [sampling overrides](java-standalone-config.md#sampling-overrides-preview) a
21472142
Use the add [custom property example](#add-a-custom-property-to-a-span), but replace the following lines of code:
21482143

21492144
```typescript
2150-
// Import the SpanKind and TraceFlags classes from the @opentelemetry/api package.
2145+
// Import the necessary packages.
21512146
const { SpanKind, TraceFlags } = require("@opentelemetry/api");
2147+
const { ReadableSpan, Span, SpanProcessor } = require("@opentelemetry/sdk-trace-base");
21522148

21532149
// Create a new SpanEnrichingProcessor class.
2154-
class SpanEnrichingProcessor {
2150+
class SpanEnrichingProcessor implements SpanProcessor {
2151+
forceFlush(): Promise<void> {
2152+
return Promise.resolve();
2153+
}
21552154

2156-
onEnd(span) {
2157-
// If the span is an internal span, set the trace flags to NONE.
2158-
if(span.kind == SpanKind.INTERNAL){
2159-
span.spanContext().traceFlags = TraceFlags.NONE;
2155+
shutdown(): Promise<void> {
2156+
return Promise.resolve();
2157+
}
2158+
2159+
onStart(_span: Span): void {}
2160+
2161+
onEnd(span) {
2162+
// If the span is an internal span, set the trace flags to NONE.
2163+
if(span.kind == SpanKind.INTERNAL){
2164+
span.spanContext().traceFlags = TraceFlags.NONE;
2165+
}
21602166
}
2161-
}
21622167
}
21632168
```
21642169

articles/azure-monitor/app/opentelemetry-configuration.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -783,22 +783,18 @@ For more information about Java, see the [Java supplemental documentation](java-
783783
```typescript
784784
// Import the useAzureMonitor function, the AzureMonitorOpenTelemetryOptions class, the trace module, the ProxyTracerProvider class, the BatchSpanProcessor class, the NodeTracerProvider class, and the OTLPTraceExporter class from the @azure/monitor-opentelemetry, @opentelemetry/api, @opentelemetry/sdk-trace-base, @opentelemetry/sdk-trace-node, and @opentelemetry/exporter-trace-otlp-http packages, respectively.
785785
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
786-
const { trace, ProxyTracerProvider } = require("@opentelemetry/api");
787786
const { BatchSpanProcessor } = require('@opentelemetry/sdk-trace-base');
788-
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
789787
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
790788

791-
// Enable Azure Monitor integration.
792-
useAzureMonitor();
793-
794789
// Create a new OTLPTraceExporter object.
795790
const otlpExporter = new OTLPTraceExporter();
796791

797-
// Get the NodeTracerProvider instance.
798-
const tracerProvider = ((trace.getTracerProvider() as ProxyTracerProvider).getDelegate() as NodeTracerProvider);
799-
800-
// Add a BatchSpanProcessor to the NodeTracerProvider instance.
801-
tracerProvider.addSpanProcessor(new BatchSpanProcessor(otlpExporter));
792+
// Enable Azure Monitor integration.
793+
const options: AzureMonitorOpenTelemetryOptions = {
794+
// Add the SpanEnrichingProcessor
795+
spanProcessors: [new BatchSpanProcessor(otlpExporter)]
796+
}
797+
useAzureMonitor(options);
802798
```
803799

804800
#### [Python](#tab/python)

0 commit comments

Comments
 (0)