Azure / Azure/azure-functions-nodejs-opentelemetry

Sample initialization code for Azure Functions + Open Telemetry doesn't work

Open
#36 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
2
Forks
11
PR merge metrics
No merged PRs in 30d

Description

**Problem 1: Inconsistent documentation**

There are 2 different sets of documentation for how to initialize OpenTelemetry with Azure functions.

Instructions on the Microsoft Learn site:
https://learn.microsoft.com/en-us/azure/azure-functions/opentelemetry-howto?tabs=app-insights%2Cihostapplicationbuilder%2Cmaven&pivots=programming-language-typescript

Instructions on this Github site:
https://github.com/Azure/azure-functions-nodejs-opentelemetry/

**Problem 2: Not all peer dependencies are included in the instructions**

When using pnpm, dependencies of dependencies aren't hoisted for use by applications.

The following dependencies are referenced in the sample code (from the MS Learn site), but not included in the list of packages that need to be installed:
@opentelemetry/instrumentation
@opentelemetry/resources
@opentelemetry/sdk-logs
@opentelemetry/sdk-trace-node

In addition, the Github instructions reference another package that would need to be installed:
@opentelemetry/instrumentation-http

**Problem 3: The example code produces multiple errors that prevent building / running:**

Errors with the MS Learn example:

@opentelemetry/resources"' has no exported member named 'detectResourcesSync'
Property 'addSpanProcessor' does not exist on type 'NodeTracerProvider'
Property 'addLogRecordProcessor' does not exist on type 'LoggerProvider'
Argument of type 'AzureMonitorLogExporter' is not assignable to parameter of type 'LogRecordExporter'.
Property 'forceFlush' is missing in type 'AzureMonitorLogExporter' but required in type 'LogRecordExporter'

Error in the Github ESM example:

Property 'addSpanProcessor' does not exist on type 'NodeTracerProvider'

For the addSpanProcessor error, it looks like the current signature for NodeTracerProvider expects for span processors to be passed to the constructor, i.e.:

```
const tracerConfig: NodeTracerConfig = {
spanProcessors: [new SimpleSpanProcessor(new AzureMonitorTraceExporter())],
};

const tracerProvider = new NodeTracerProvider(tracerConfig);
tracerProvider.register();
```

Instead of:
```
const tracerProvider = new NodeTracerProvider();
tracerProvider.addSpanProcessor(new SimpleSpanProcessor(new AzureMonitorTraceExporter()));
tracerProvider.register();
```

Contributor guide

Open the contributing guide

Research direction

Compare the Microsoft Learn OpenTelemetry instructions with the azure-functions-nodejs-opentelemetry GitHub instructions, starting from their sample initialization code and package lists. Reproduce the reported pnpm dependency and TypeScript errors, then verify that the examples build and run with the documented dependencies and current OpenTelemetry APIs.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, typescript
Domain
backend, observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.