microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Beta] - How to add custom instrumentation?

marcus13371337 opened this issue · comments

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

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(),
    ],
  });