@@ -1725,17 +1725,9 @@ Adding one or more span attributes populates the `customDimensions` field in the
1725
1725
``` typescript
1726
1726
// Import the necessary packages.
1727
1727
const { useAzureMonitor } = require (" @azure/monitor-opentelemetry" );
1728
- const { trace, ProxyTracerProvider } = require (" @opentelemetry/api" );
1729
1728
const { ReadableSpan, Span, SpanProcessor } = require (" @opentelemetry/sdk-trace-base" );
1730
- const { NodeTracerProvider } = require (" @opentelemetry/sdk-trace-node" );
1731
1729
const { SemanticAttributes } = require (" @opentelemetry/semantic-conventions" );
1732
1730
1733
- // Enable Azure Monitor integration.
1734
- useAzureMonitor ();
1735
-
1736
- // Get the NodeTracerProvider instance.
1737
- const tracerProvider = ((trace .getTracerProvider () as ProxyTracerProvider ).getDelegate () as NodeTracerProvider );
1738
-
1739
1731
// Create a new SpanEnrichingProcessor class.
1740
1732
class SpanEnrichingProcessor implements SpanProcessor {
1741
1733
forceFlush(): Promise <void > {
@@ -1755,8 +1747,13 @@ class SpanEnrichingProcessor implements SpanProcessor {
1755
1747
}
1756
1748
}
1757
1749
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
+
1760
1757
```
1761
1758
1762
1759
##### [ Python] ( #tab/python )
@@ -1960,29 +1957,27 @@ Logback, Log4j, and java.util.logging are [autoinstrumented](#logs). Attaching c
1960
1957
#### [ Node.js] ( #tab/nodejs )
1961
1958
1962
1959
``` typescript
1963
- // Import the useAzureMonitor function and the logs module from the @azure/monitor-opentelemetry and @opentelemetry/api-logs packages, respectively.
1964
1960
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' );
1967
1962
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
+ };
1970
1970
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 );
1973
1973
1974
- // Create a new log record.
1975
- const logRecord = {
1976
- body: " testEvent" ,
1977
- attributes: {
1974
+ var log = bunyan .createLogger ({ name: ' testApp' });
1975
+ log .info ({
1978
1976
" testAttribute1" : " testValue1" ,
1979
1977
" testAttribute2" : " testValue2" ,
1980
1978
" testAttribute3" : " testValue3"
1981
- }
1982
- };
1979
+ }, ' testEvent' );
1983
1980
1984
- // Emit the log record.
1985
- logger .emit (logRecord );
1986
1981
```
1987
1982
1988
1983
#### [ Python] ( #tab/python )
@@ -2147,18 +2142,28 @@ See [sampling overrides](java-standalone-config.md#sampling-overrides-preview) a
2147
2142
Use the add [custom property example ](#add - a - custom - property - to - a - span ), but replace the following lines of code :
2148
2143
2149
2144
```typescript
2150
- // Import the SpanKind and TraceFlags classes from the @opentelemetry/api package .
2145
+ // Import the necessary packages .
2151
2146
const { SpanKind , TraceFlags } = require (" @opentelemetry/api" );
2147
+ const { ReadableSpan , Span , SpanProcessor } = require (" @opentelemetry/sdk-trace-base" );
2152
2148
2153
2149
// Create a new SpanEnrichingProcessor class.
2154
- class SpanEnrichingProcessor {
2150
+ class SpanEnrichingProcessor implements SpanProcessor {
2151
+ forceFlush (): Promise < void > {
2152
+ return Promise .resolve ();
2153
+ }
2155
2154
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
+ }
2160
2166
}
2161
- }
2162
2167
}
2163
2168
```
2164
2169
0 commit comments