-
Couldn't load subscription status.
- Fork 2
feat: Add basic config for dotnet plugin. #167
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a61fabe
chore: Scaffold dotnet plugin project.
kinyoklion bbb61dc
Add dotnet setup step and correct working directory.
kinyoklion 7bb9496
Explicit permissions.
kinyoklion f694eb1
Reformat workflow file.
kinyoklion f9544cd
Add project reference to implementation from tests.
kinyoklion a012647
feat: Add basic configuration and otel.
kinyoklion da1036d
Merge branch 'main' into rlamb/add-basic-config-dotnet
kinyoklion a3b435f
PR feedback.
kinyoklion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| **/bin | ||
| **/obj | ||
| LaunchDarkly.Observability.sln.DotSettings.user | ||
| **/launchSettings.json |
18 changes: 18 additions & 0 deletions
18
sdk/@launchdarkly/observability-dotnet/AspSampleApp/AspSampleApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.19"/> | ||
| <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\src\LaunchDarkly.Observability\LaunchDarkly.Observability.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
6 changes: 6 additions & 0 deletions
6
sdk/@launchdarkly/observability-dotnet/AspSampleApp/AspSampleApp.http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @AspSampleApp_HostAddress = http://localhost:5247 | ||
|
|
||
| GET {{AspSampleApp_HostAddress}}/weatherforecast/ | ||
| Accept: application/json | ||
|
|
||
| ### |
54 changes: 54 additions & 0 deletions
54
sdk/@launchdarkly/observability-dotnet/AspSampleApp/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using LaunchDarkly.Observability; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| // Add services to the container. | ||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
| builder.Services.AddEndpointsApiExplorer(); | ||
| builder.Services.AddSwaggerGen(); | ||
| builder.Services.AddLaunchDarklyObservability( | ||
| Environment.GetEnvironmentVariable("LAUNCHDARKLY_SDK_KEY"), | ||
| ldBuilder => | ||
| { | ||
| ldBuilder.WithServiceName("ryan-test-service"); | ||
| } | ||
| ); | ||
|
|
||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| // Configure the HTTP request pipeline. | ||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| app.UseSwagger(); | ||
| app.UseSwaggerUI(); | ||
| } | ||
|
|
||
| app.UseHttpsRedirection(); | ||
|
|
||
| var summaries = new[] | ||
| { | ||
| "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
| }; | ||
|
|
||
| app.MapGet("/weatherforecast", () => | ||
| { | ||
| var forecast = Enumerable.Range(1, 5).Select(index => | ||
| new WeatherForecast | ||
| ( | ||
| DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | ||
| Random.Shared.Next(-20, 55), | ||
| summaries[Random.Shared.Next(summaries.Length)] | ||
| )) | ||
| .ToArray(); | ||
| return forecast; | ||
| }) | ||
| .WithName("GetWeatherForecast") | ||
| .WithOpenApi(); | ||
|
|
||
| app.Run(); | ||
|
|
||
| record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) | ||
| { | ||
| public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
sdk/@launchdarkly/observability-dotnet/AspSampleApp/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
sdk/@launchdarkly/observability-dotnet/AspSampleApp/appsettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
sdk/@launchdarkly/observability-dotnet/src/LaunchDarkly.Observability/ObservabilityConfig.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| namespace LaunchDarkly.Observability | ||
| { | ||
| public struct ObservabilityConfig | ||
| { | ||
| /// <summary> | ||
| /// The configured OTLP endpoint. | ||
| /// </summary> | ||
| public string OtlpEndpoint { get; } | ||
|
|
||
| /// <summary> | ||
| /// The configured back-end URL. | ||
| /// <para> | ||
| /// This is used for non-telemetry operations such as accessing the sampling configuration. | ||
| /// </para> | ||
| /// </summary> | ||
| public string BackendUrl { get; } | ||
| /// <summary> | ||
| /// The name of the service. | ||
| /// <para> | ||
| /// The service name is used for adding resource attributes. If a service name is not defined, then the | ||
| /// service version will also not be included in the resource attributes. | ||
| /// </para> | ||
| /// </summary> | ||
| public string ServiceName { get; } | ||
| /// <summary> | ||
| /// The version of the service. | ||
| /// </summary> | ||
| public string ServiceVersion { get; } | ||
| /// <summary> | ||
| /// The environment for the service. | ||
| /// </summary> | ||
| public string Environment { get; } | ||
| /// <summary> | ||
| /// The LaunchDarkly SDK key. | ||
| /// </summary> | ||
| public string SdkKey { get; } | ||
|
|
||
| private ObservabilityConfig( | ||
| string otlpEndpoint, | ||
| string backendUrl, | ||
| string serviceName, | ||
| string environment, | ||
| string serviceVersion, | ||
| string sdkKey) | ||
| { | ||
| OtlpEndpoint = otlpEndpoint; | ||
| BackendUrl = backendUrl; | ||
| ServiceName = serviceName; | ||
| Environment = environment; | ||
| ServiceVersion = serviceVersion; | ||
| SdkKey = sdkKey; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Create a new builder for <see cref="ObservabilityConfig"/>. | ||
| /// </summary> | ||
| /// <param name="sdkKey">The LaunchDarkly SDK key used for authentication and resource attributes.</param> | ||
| /// <returns>A new <see cref="Builder"/> instance for configuring observability.</returns> | ||
| internal static Builder CreateBuilder(string sdkKey) => new Builder(sdkKey); | ||
|
|
||
| /// <summary> | ||
| /// Fluent builder for <see cref="ObservabilityConfig"/>. | ||
| /// </summary> | ||
| public sealed class Builder | ||
| { | ||
| private const string DefaultOtlpEndpoint = "https://otel.observability.app.launchdarkly.com:4318"; | ||
| private const string DefaultBackendUrl = "https://pub.observability.app.launchdarkly.com"; | ||
| private string _otlpEndpoint = DefaultOtlpEndpoint; | ||
| private string _backendUrl = DefaultBackendUrl; | ||
| private string _serviceName = string.Empty; | ||
| private string _environment = string.Empty; | ||
| private string _serviceVersion = string.Empty; | ||
| private readonly string _sdkKey; | ||
|
|
||
| internal Builder(string sdkKey) | ||
| { | ||
| this._sdkKey = sdkKey; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Set the OTLP endpoint. | ||
| /// <para> | ||
| /// For most configurations, the OTLP endpoint will not need to be set. | ||
| /// </para> | ||
| /// <para> | ||
| /// Setting the endpoint to null will reset the builder value to the default. | ||
| /// </para> | ||
| /// </summary> | ||
| /// <param name="otlpEndpoint">The OTLP exporter endpoint URL.</param> | ||
| /// <returns>A reference to this builder.</returns> | ||
| public Builder WithOtlpEndpoint(string otlpEndpoint) | ||
| { | ||
| _otlpEndpoint = otlpEndpoint ?? DefaultOtlpEndpoint; | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Set the back-end URL for non-telemetry operations. | ||
| /// <para> | ||
| /// For most configurations, the backend url will not need to be set. | ||
| /// </para> | ||
| /// <para> | ||
| /// Setting the url to null will reset the builder value to the default. | ||
| /// </para> | ||
| /// </summary> | ||
| /// <param name="backendUrl">The back-end URL used for non-telemetry operations.</param> | ||
| /// <returns>A reference to this builder.</returns> | ||
| public Builder WithBackendUrl(string backendUrl) | ||
| { | ||
| _backendUrl = backendUrl ?? DefaultBackendUrl; | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Set the service name. | ||
| /// </summary> | ||
| /// <param name="serviceName">The logical service name used in telemetry resource attributes.</param> | ||
| /// <returns>A reference to this builder.</returns> | ||
| public Builder WithServiceName(string serviceName) | ||
| { | ||
| _serviceName = serviceName ?? string.Empty; | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Set the service version. | ||
| /// </summary> | ||
| /// <param name="serviceVersion"> | ||
| /// The version of the service that will be added to resource attributes when a service name is provided. | ||
| /// </param> | ||
| /// <returns>A reference to this builder.</returns> | ||
| public Builder WithServiceVersion(string serviceVersion) | ||
| { | ||
| _serviceVersion = serviceVersion ?? string.Empty; | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Set the environment name. | ||
| /// </summary> | ||
| /// <param name="environment">The environment name (for example, "prod" or "staging").</param> | ||
| /// <returns>A reference to this builder.</returns> | ||
| public Builder WithEnvironment(string environment) | ||
| { | ||
| _environment = environment ?? string.Empty; | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Build an immutable <see cref="ObservabilityConfig"/> instance. | ||
| /// </summary> | ||
| /// <returns>The constructed <see cref="ObservabilityConfig"/>.</returns> | ||
| public ObservabilityConfig Build() | ||
| { | ||
| return new ObservabilityConfig( | ||
| _otlpEndpoint, | ||
| _backendUrl, | ||
| _serviceName, | ||
| _environment, | ||
| _serviceVersion, | ||
| _sdkKey); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.