From 08648d923782752b2bb230d1653e072eadbffad0 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Mon, 8 May 2023 11:10:07 -0700 Subject: [PATCH] Add other exportes example (#1141) --- README.md | 15 +++++++++++++++ src/traces/traceHandler.ts | 3 +-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ff3adda03..157b7f141 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,21 @@ Other OpenTelemetry Instrumentations are available [here](https://github.com/ope ``` +## Add other OpenTelemetry Exporters + +You can include other OpenTelemetry Exporters adding a new SpanProcessor to the TracerProvider created internally: + +```typescript +const { ApplicationInsightsClient, ApplicationInsightsConfig } = require("applicationinsights"); +const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http'); +const { BatchSpanProcessor } = require("@opentelemetry/sdk-trace-base"); + +const appInsights = new ApplicationInsightsClient(new ApplicationInsightsConfig()); +const otlpExporter = new OTLPTraceExporter(collectorOptions); +const spanProcessor = new BatchSpanProcessor(otlpExporter); +appInsights.getTraceHandler().addSpanProcessor(spanProcessor); +``` + ## Set the Cloud Role Name and the Cloud Role Instance You might set the Cloud Role Name and the Cloud Role Instance via [OpenTelemetry Resource](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-sdk) attributes. This step updates Cloud Role Name and Cloud Role Instance from their default values to something that makes sense to your team. They'll appear on the Application Map as the name underneath a node. Cloud Role Name uses `service.namespace` and `service.name` attributes, although it falls back to `service.name` if `service.namespace` isn't set. Cloud Role Instance uses the `service.instance.id` attribute value. diff --git a/src/traces/traceHandler.ts b/src/traces/traceHandler.ts index 4c0e99936..bf047e979 100644 --- a/src/traces/traceHandler.ts +++ b/src/traces/traceHandler.ts @@ -17,7 +17,6 @@ import { BatchSpanProcessor, BufferConfig, SpanProcessor, Tracer } from "@opente import { HttpInstrumentation, HttpInstrumentationConfig, IgnoreOutgoingRequestFunction } from "@opentelemetry/instrumentation-http"; import { ApplicationInsightsSampler } from "./applicationInsightsSampler"; import { ApplicationInsightsConfig } from "../shared"; -import { TracerProvider } from "@opentelemetry/api"; import { MetricHandler } from "../metrics/metricHandler"; import { AzureSpanProcessor } from "./azureSpanProcessor"; import { AzureFunctionsHook } from "./azureFunctionsHook"; @@ -88,7 +87,7 @@ export class TraceHandler { // No Op } - public getTracerProvider(): TracerProvider { + public getTracerProvider(): NodeTracerProvider { return this._tracerProvider; }