microsoft / microsoft/aspire

otel service name is not taken into account in Azure, locally it is working

Open
#8,522 1 comment 0 reactions 0 assignees View on GitHub
needs-area-label
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Hi,

I have a nextJS frontend which initializes `service-name` correctly using following code for local development and production environment:

```javascript
// instrumentation.local.node.ts
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-grpc";
import { resourceFromAttributes } from "@opentelemetry/resources";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { SimpleSpanProcessor } from "@opentelemetry/sdk-trace-node";
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";

const serviceName = process.env.SERVER_OTEL_SERVICE_NAME;
console.log(`Using service name: ${serviceName} for tracing`);
// Uses grpc to export collected traces.
const sdk = new NodeSDK({
resource: resourceFromAttributes({
[ATTR_SERVICE_NAME]: serviceName,
}),
spanProcessors: [new SimpleSpanProcessor(new OTLPTraceExporter())],
});
sdk.start();
```

```javascript
// instrumentation.node.ts
import { AzureMonitorTraceExporter } from "@azure/monitor-opentelemetry-exporter";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-grpc";
import { resourceFromAttributes } from "@opentelemetry/resources";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
import { ErrorOrSampleProcessor } from "./errorOrSampleProcessor";

const exporter = new AzureMonitorTraceExporter({
connectionString: process.env.AZURE_MONITOR_CONNECTION_STRING,
}) as any;

const otlpExporter = new OTLPTraceExporter();
const serviceName = process.env.SERVER_OTEL_SERVICE_NAME;

console.log(`Using service name: ${serviceName} for tracing`);
// Uses grpc to export collected traces.
const sdk = new NodeSDK({
resource: resourceFromAttributes({
[ATTR_SERVICE_NAME]: serviceName,
}),
spanProcessors: [new ErrorOrSampleProcessor(exporter, 0.05), new ErrorOrSampleProcessor(otlpExporter, 0.05)],
});
sdk.start();
```

If I run everything locally the `service-name` is correctly set and `service.name` is correctly shown in the .NET Aspire Dashboard:

![Image](https://github.com/user-attachments/assets/2c00f5d2-0c08-4ec4-bda9-dd91c6d48a89)

In Azure I've just enabled the dashboard in my Container App Environment. I haven't deployed any aspire dashboard myself. Anyway the `service.name` is there set to the name of the container app:

![Image](https://github.com/user-attachments/assets/d1f7621d-0a1b-4761-a2d4-38246df44edb)

I've double checked that the env var `SERVER_OTEL_SERVICE_NAME` is correctly set to `next-backend` during the deployment process. Locally I've used the `9.1` docker image. I've tested it locally with the `9.0` image as well and the behaviour is the same. The remote version in Azure is `Version: 9.0.1-dev`.

Is the aspire dashboard in azure maybe not taking the manual set `service.name` taking into account?

To be honest I have no clue how to reproduce the issue locally. If any more info is needed I'm happy to provide these.

Thanks for the great work with the .NET Aspire Dashboard.

### Expected Behavior

I expect that `service.name` is correctly set as it is working on my local machine.

### Steps To Reproduce

Locally I haven't found a way to reproduce the behaviour.

### Exceptions (if any)

No exceptions shown anywhere.

### .NET Version info

The .NET backend uses .NET 8

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.