microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
320 stars 138 forks source link

[Beta] - How to add custom instrumentation? #1222

Closed marcus13371337 closed 2 months ago

marcus13371337 commented 9 months ago

Nice with new versions, and that you are keeping up getting tracing into app services! However, I tried to go from 3.0.0-beta.6 to 3.0.0-beta.9. But I'm having a really hard time to converting my old config to your new format. As an example, how do I add a custom instrumentation? I.e what was described here in 3.0.0-beta.6

TheIceCreamTroll commented 8 months ago

Telemetry can now be added through the Open Telemetry Instrumentation package. Here's an example:

import { AzureMonitorOpenTelemetryOptions, useAzureMonitor } from 'applicationinsights';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql';
import { DataloaderInstrumentation } from '@opentelemetry/instrumentation-dataloader';

  const config: AzureMonitorOpenTelemetryOptions = {
    azureMonitorExporterOptions: {
      connectionString: process.env[process.env.APPLICATIONINSIGHTS_CONNECTION_STRING],
    }
  }

  useAzureMonitor(config); // Must be BEFORE instrumentation registration

registerInstrumentations({
    instrumentations: [
      new GraphQLInstrumentation({ allowValues: true, }),
      new DataloaderInstrumentation(),
    ],
  });
JacksonWeber commented 2 months ago

Closing as the question was answered in this thread.