Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update metrics sample to use OTLP and OTEL collector #606

Merged
merged 9 commits into from
Dec 6, 2024

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Dec 4, 2024

The metrics sample today configures the developer app to expose a Prometheus scrape endpoint, and configures Prometheus to periodically scrape the endpoint for new data.

This PR changes the developer app to instead send telemetry to Prometheus using OTLP.

  • Before: Prometheus calls the app to get telemetry from the scrape endpoint
  • After: App sends telemetry to Prometheus, which is more consistent with how other telemetry exports work

Because OTLP can only be sent to one endpoint by .NET OTEL SDK, the PR also adds the OpenTelemetry Collector to the app host. A lifecycle hook updates all developer apps to send telemetry to the collector, which then forwards it to the Aspire dashboard and Prometheus.

@JamesNK JamesNK force-pushed the jamesnk/otelcollector branch from 7cd7364 to a7fb5ff Compare December 4, 2024 23:12
Comment on lines -49 to +50
var certFileDest = Path.Combine(DEV_CERT_BIND_MOUNT_DEST_DIR, certFileName);
var certKeyFileDest = Path.Combine(DEV_CERT_BIND_MOUNT_DEST_DIR, certKeyFileName);
var certFileDest = $"{DEV_CERT_BIND_MOUNT_DEST_DIR}/{certFileName}";
var certKeyFileDest = $"{DEV_CERT_BIND_MOUNT_DEST_DIR}/{certKeyFileName}";
Copy link
Member Author

@JamesNK JamesNK Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI Path.Combine would add backslash when app host is run on Windows.

e.g. /dev-cert\dev-cert.pem

The OpenTelemetry collector errored when given the bad path. Seems best to hardcode to forward slash.

Copy link
Member

@DamianEdwards DamianEdwards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

return Task.CompletedTask;
}

foreach (var resource in appModel.GetProjectResources())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this check all resources? In the callback it would then check if OTEL_EXPORTER_OTLP_ENDPOINT is set and replace it with this value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that OTEL_EXPORTER_OTLP_ENDPOINT env var is added by a callback. At the resource level we don't know exactly what env vars there are from a callback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do work in the callback to look at what has been set.

@JamesNK JamesNK merged commit 0c27e4e into main Dec 6, 2024
3 checks passed
@JamesNK JamesNK deleted the jamesnk/otelcollector branch December 6, 2024 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants