-
Notifications
You must be signed in to change notification settings - Fork 221
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
Conversation
samples/Metrics/MetricsApp.AppHost/OpenTelemetryCollector/CollectorResourceBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
samples/Metrics/MetricsApp.AppHost/OpenTelemetryCollector/CollectorResourceBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
samples/Metrics/MetricsApp.AppHost/OpenTelemetryCollector/CollectorResourceBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
samples/Metrics/MetricsApp.AppHost/OpenTelemetryCollector/CollectorResourceBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
7cd7364
to
a7fb5ff
Compare
...MetricsApp.AppHost/OpenTelemetryCollector/OpenTelemetryCollectorResourceBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
samples/Metrics/grafana/config/provisioning/datasources/default.yaml
Outdated
Show resolved
Hide resolved
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}"; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
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.