Skip to content

Commit

Permalink
get fetch autoinstrumentation working
Browse files Browse the repository at this point in the history
  • Loading branch information
Grunet authored Apr 5, 2023
1 parent 30784d2 commit 8cbcc12
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { Resource } from 'npm:@opentelemetry/resources';
import { SemanticResourceAttributes } from 'npm:@opentelemetry/semantic-conventions';
import { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } from 'npm:@opentelemetry/sdk-trace-base';
// const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
import { FetchInstrumentation } from 'npm:@opentelemetry/instrumentation-fetch';
import { registerInstrumentations } from 'npm:@opentelemetry/instrumentation';

// Monkeypatching to get past FetchInstrumentation's dependence on sdk-trace-web, which depends on some browser-only constructs
globalThis.location = {}; //For this line - /~https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-sdk-trace-web/src/utils.ts#L310

const provider = new BasicTracerProvider({
resource: new Resource({
Expand All @@ -27,6 +32,11 @@ provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
* methods will receive no-op implementations.
*/
provider.register();

registerInstrumentations({
instrumentations: [new FetchInstrumentation()],
});

const tracer = opentelemetry.trace.getTracer('example-basic-tracer-node');

// Create a span. A span must be closed.
Expand Down

0 comments on commit 8cbcc12

Please sign in to comment.