-
Notifications
You must be signed in to change notification settings - Fork 119
Add OpenTelemetry Collector extension/component #603
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
Add OpenTelemetry Collector extension/component #603
Conversation
@dotnet-policy-service agree |
I'm not sure how ready this is yet. I've been playing with the API a bit to give it enough flexibility around the certificates, images and config files. Feedback very welcome, I wanted to get this up as is before I added any tests and worked on the documentation, etc. |
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.
Would it make sense that, rather than having a default collector image set, that it's a required property to be provided and there's a method that will set the defaults for you?
So, AddOpenTelemetryCollector
is used if you want to specify a collector, whereas AddOpenTelemetryDefaultCollection
uses the one that you have currently specified as a default.
...Hosting.OpenTelemetryCollector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.csproj
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableHook.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableHook.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableHook.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableHook.cs
Outdated
Show resolved
Hide resolved
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.
File no longer needed
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/PublicAPI.Unshipped.txt
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/DevCertHostingExtensions.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/OpenTelemetryCollectorSettings.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/OpenTelemetryCollectorSettings.cs
Outdated
Show resolved
Hide resolved
Interesting approach, I'm honestly not sure, but maybe a I was thinking that the approach I showed was more common, but happy if not. I kinda wanted a minimal default command though. |
The problem with a method like |
I agree it's not ideal, but I'd prefer to not have them need to know what the image link is to collector. So I believe the best option is to use the default image we recommend in Otel right now (which is |
7ac9a9d
to
a38c078
Compare
I'm coming back at this now @aaronpowell, with a hope to move it forward so I don't need to maintain a separate one (happy to be codeowner here). On the devcerts, it seems those issues haven't got a resolution, would it be ok to leave the devcerts in this project for now, and consolidate/move later? This project would actually fix both of those issues as the users could run the non-ssl collector and forward their data through the collector as a way to unblock them. The big outstanding issue is the collector image model, can you let me know what you'd suggest there. It should be |
If you can pop it in the
What's the release frequency that they are going with? The main reason that we pin to a version is so that we don't risk any unexpected changes to command line args or other behaviour getting introduced that impact someone who hasn't opt-ed in to using a newer version. If they are releasing new versions daily, then pinned isn't ideal, but generally speaking, pinning a version is going to be preferred, and people can always specify a version override if we don't release an updated package quick enough (Ollama is a good example of where we get caught on that front). |
The release cycle for the collector is every 2 weeks. The compatibility issues wouldn't be commandline args, its more likely the config of collector components that might change, but we haven't done a breaking change in about 6 months and those are expected to be the last. The biggest issue with pinning a version is security issues, since the amount of components in the collector means that the updates contain those updates regularly. I'll happily take guidance on what the best way to get this published is. |
0ae0e03
to
7c26b63
Compare
I've done a few major updates, so it probably needs a full re-review.
This does require the user to implement |
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.
Pull Request Overview
This PR adds an OpenTelemetry Collector integration to the .NET Aspire Community Toolkit, enabling users to add an OpenTelemetry Collector container to their Aspire applications for observability data collection and forwarding.
- Introduces a new hosting integration with configurable settings for the OpenTelemetry Collector
- Provides automatic HTTPS certificate handling for secure connections in development mode
- Implements environment variable hooks to automatically configure project resources to send telemetry data to the collector
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
src/Shared/DevCertHostingExtensions.cs | Shared utility for injecting ASP.NET Core HTTPS dev certificates into resources via environment variables |
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/OpenTelemetryCollectorSettings.cs | Configuration settings class for the OpenTelemetry Collector |
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableHook.cs | Lifecycle hook to automatically configure project resources with collector endpoints |
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.csproj | Project file for the OpenTelemetry Collector integration |
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CollectorResource.cs | Resource definition for the OpenTelemetry Collector container |
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CollectorExtensions.cs | Extension methods for adding and configuring the OpenTelemetry Collector |
CommunityToolkit.Aspire.slnx | Solution file updated to include the new project |
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableHook.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableHook.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CollectorExtensions.cs
Outdated
Show resolved
Hide resolved
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 main change here would be to use the event callbacks of 9.4.
Then would you be able to introduce an example project so I can get a better idea of how this works.
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CollectorExtensions.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableHook.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableHook.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/OpenTelemetryCollectorSettings.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CollectorExtensions.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CollectorResource.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CollectorResource.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CollectorResource.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableHook.cs
Outdated
Show resolved
Hide resolved
I've done everything suggested other than moving the EnvironmentVariableHook. Since this needs to occur after all the resources had endpoints allocated, I'm struggling to see how I might achieve that. I did have a thought of using OnAfterEndpointsAllocatedEvent, but that's deprecated, and then thought of using |
Yes, sorry, I was mistaken, Is the logic that you'd have multiple collectors registered, or is it a singleton sort of thing? |
The collector is a service that intercepts the OTLP telemetry from all the other services, so it intercepts all the other project resources and overrides the OTLP environment variable to point it to the collector instead. For that reason, I thought that using the resource focused events wasn't something I could do. This is instead of telling the user to access every resource and reference it to the collector. |
@davidfowl let me know what you think of the new DevCerts code. I used yours as a base and updated it with optional parameters. If thats OK, I'll build out the examples. |
5d2da46
to
5f9f442
Compare
Other than tests, I think this is pretty much there now @aaronpowell @davidfowl I've struggled with the tests because the main thing to test is the AppForwarding (testing that all OTHER resources have their OTEL endpoint environment variables updated to point to the collector). This means that the endpoints need to be allocated in the collector before the event is fired. The only other tests I can think of that would be beneficial are the environment variables for the Dashboard endpoints, and the devcerts, I'm not sure how we can test those. If you've got pointers on the tests then please let me know! |
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableEvent.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/EnvironmentVariableEvent.cs
Outdated
Show resolved
Hide resolved
Looks like it should all be resolved now. |
Tests need to be added to the workflow file, since we run a job-per-test. Check https://github.com/CommunityToolkit/Aspire/actions/runs/17362288128/job/49289169742?pr=603#step:4:11 |
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 only thing I'd like to see is more tests included.
I understand that it's hard to test the running of this integration, so instead, let's focus the tests on the API surface area and that the things it does are what we expect.
We can have tests that the appropriate annotations are setup and that the devcert stuff can be configured (again, probably looking at annotations, maybe at the additional resource is included).
I've added some more tests. I don't think we'll be able to test the DevCerts because it requires run mode. This is because the annotations being added are based on the output from the DevCerts extraction. I suppose we could change the code to make that do something "dummy" during non-run mode? However, that doesn't feel like the right thing to do? |
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.
I have added a bunch more tests which sees the coverage boosted to a bit over 60% (which is our target).
@martinjt can you have a look over the tests to see if they make sense. Also, are you going to go down as the code owner, if so, can you add yourself to the CODEOWNERS file and I'll sort out the permissions.
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../CommunityToolkit.Aspire.Testing/CommunityToolkit.Aspire.Testing.csproj" /> |
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.
..\
../
😄
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.
Go complain to the editor teams - I added the reference via devkit on my devcontainer 😝
if (!settings.ForceNonSecureReceiver && isHttpsEnabled && builder.ExecutionContext.IsRunMode && builder.Environment.IsDevelopment()) | ||
{ | ||
resourceBuilder.RunWithHttpsDevCertificate(); | ||
var certFilePath = Path.Combine(DevCertHostingExtensions.DEV_CERT_BIND_MOUNT_DEST_DIR, DevCertHostingExtensions.CERT_FILE_NAME); |
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.
I believe there is an issue with these two lines. On Windows, Path.Combine uses two backslashes, which causes the collector container to fall-over on startup, complaining about yaml format. I've tried replacing the line with a string.Join('/', ...)
to force it to use forward slashes, which works correctly, e.g.
var certFilePath = string.Join('/', DevCertHostingExtensions.DEV_CERT_BIND_MOUNT_DEST_DIR, DevCertHostingExtensions.CERT_FILE_NAME);
Not the most elegant approach, but it has fixed the issue.
**Closes #602 **
PR Checklist
Other information