-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
github-actions
committed
Mar 26, 2022
1 parent
34d3726
commit 1888a8a
Showing
94 changed files
with
74,861 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
21 changes: 21 additions & 0 deletions
21
src/Aguacongas.TheIdServer/Extensions/ServiceCollectionExtensions.cs
This file contains 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,21 @@ | ||
using Aguacongas.TheIdServer.Options.OpenTelemetry; | ||
using Microsoft.Extensions.Configuration; | ||
using OpenTelemetry.Trace; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddOpenTelemetry(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
var options = configuration.Get<OpenTelemetryOptions>(); | ||
return services.AddOpenTelemetry(options); | ||
} | ||
|
||
public static IServiceCollection AddOpenTelemetry(this IServiceCollection services, OpenTelemetryOptions options) | ||
=> services.AddOpenTelemetryTracing(builder => | ||
{ | ||
builder.AddTheIdServerTelemetry(options); | ||
}); | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
src/Aguacongas.TheIdServer/Extensions/TracerProviderBuilderExtensions.cs
This file contains 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,155 @@ | ||
using Aguacongas.TheIdServer.Options.OpenTelemetry; | ||
using Honeycomb.OpenTelemetry; | ||
using OpenTelemetry.Resources; | ||
using StackExchange.Redis; | ||
|
||
namespace OpenTelemetry.Trace | ||
{ | ||
public static class TracerProviderBuilderExtensions | ||
{ | ||
public static TracerProviderBuilder AddTheIdServerTelemetry(this TracerProviderBuilder builder, OpenTelemetryOptions options) | ||
{ | ||
if (options.ConsoleEnabled) | ||
{ | ||
builder = builder.AddConsoleExporter(); | ||
} | ||
|
||
return builder.AddExporters(options.Exporter) | ||
.AddSource(options.Service.Name) | ||
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(options.Service.Name, | ||
options.Service.Namespace, | ||
options.Service.Version, | ||
options.Service.AutoGenerateServiceInstanceId, | ||
options.Service.InstanceId)) | ||
.AddInstrumentation(options.Instrumentation); | ||
} | ||
|
||
public static TracerProviderBuilder AddInstrumentation(this TracerProviderBuilder builder, InstrumentationOptions options) | ||
{ | ||
builder = builder.AddHttpClientInstrumentation(o => | ||
{ | ||
var httpClientOptions = options?.HttpClient; | ||
if (httpClientOptions is null) | ||
{ | ||
return; | ||
} | ||
o.SetHttpFlavor = httpClientOptions.SetHttpFlavor; | ||
o.RecordException = httpClientOptions.RecordException; | ||
}) | ||
.AddAspNetCoreInstrumentation(o => | ||
{ | ||
var aspOptions = options?.AspNetCore; | ||
if (aspOptions is null) | ||
{ | ||
return; | ||
} | ||
o.RecordException = aspOptions.RecordException; | ||
o.EnableGrpcAspNetCoreSupport = aspOptions.EnableGrpcAspNetCoreSupport; | ||
}) | ||
.AddSqlClientInstrumentation(o => | ||
{ | ||
var sqlClientOptions = options?.SqlClient; | ||
if (sqlClientOptions is null) | ||
{ | ||
return; | ||
} | ||
o.RecordException = sqlClientOptions.RecordException; | ||
o.EnableConnectionLevelAttributes = sqlClientOptions.EnableConnectionLevelAttributes; | ||
o.SetDbStatementForText = sqlClientOptions.SetDbStatementForText; | ||
o.SetDbStatementForStoredProcedure = sqlClientOptions.SetDbStatementForStoredProcedure; | ||
}); | ||
|
||
if (!string.IsNullOrEmpty(options?.Redis?.ConnectionString)) | ||
{ | ||
var connection = ConnectionMultiplexer.Connect(options.Redis.ConnectionString); | ||
builder = builder.AddRedisInstrumentation(connection, o => | ||
{ | ||
var redisOptions = options?.Redis; | ||
if (redisOptions is null) | ||
{ | ||
return; | ||
} | ||
o.FlushInterval = redisOptions.FlushInterval; | ||
o.SetVerboseDatabaseStatements = redisOptions.SetVerboseDatabaseStatements; | ||
}); | ||
} | ||
|
||
return builder; | ||
} | ||
private static TracerProviderBuilder AddExporters(this TracerProviderBuilder builder, ExporterOptions options) | ||
{ | ||
if (options is null) | ||
{ | ||
return builder; | ||
} | ||
|
||
if (!string.IsNullOrEmpty(options.Jaeger?.AgentHost)) | ||
{ | ||
builder = builder.AddJaegerExporter(o => | ||
{ | ||
var jaegerOptions = options.Jaeger; | ||
o.AgentPort = jaegerOptions.AgentPort; | ||
o.AgentHost = jaegerOptions.AgentHost; | ||
o.BatchExportProcessorOptions = jaegerOptions.BatchExportProcessorOptions; | ||
o.ExportProcessorType = jaegerOptions.ExportProcessorType; | ||
}); | ||
} | ||
|
||
if (options.OpenTelemetryProtocol?.Endpoint is not null) | ||
{ | ||
builder = builder.AddOtlpExporter(o => | ||
{ | ||
var otlpOptions = options.OpenTelemetryProtocol; | ||
o.BatchExportProcessorOptions = otlpOptions.BatchExportProcessorOptions; | ||
o.ExportProcessorType = otlpOptions.ExportProcessorType; | ||
o.Endpoint = otlpOptions.Endpoint; | ||
o.Headers = otlpOptions.Headers; | ||
}); | ||
} | ||
|
||
if (options.Zipkin?.Endpoint is not null) | ||
{ | ||
builder = builder.AddZipkinExporter(o => | ||
{ | ||
var zipkinOptions = options.Zipkin; | ||
o.ExportProcessorType = zipkinOptions.ExportProcessorType; | ||
o.BatchExportProcessorOptions = zipkinOptions.BatchExportProcessorOptions; | ||
o.Endpoint = zipkinOptions.Endpoint; | ||
o.MaxPayloadSizeInBytes = zipkinOptions.MaxPayloadSizeInBytes; | ||
o.UseShortTraceIds = zipkinOptions.UseShortTraceIds; | ||
}); | ||
} | ||
|
||
if (options.Honeycomb?.ApiKey is not null) | ||
{ | ||
builder = builder.AddHoneycomb(o => | ||
{ | ||
var honeycombOptions = options.Honeycomb; | ||
o.ApiKey = honeycombOptions.ApiKey; | ||
o.TracesApiKey = honeycombOptions.TracesApiKey; | ||
o.MetricsApiKey = honeycombOptions.MetricsApiKey; | ||
o.Dataset = honeycombOptions.Dataset; | ||
o.TracesDataset = honeycombOptions.TracesDataset; | ||
o.MetricsDataset = honeycombOptions.MetricsDataset; | ||
o.Endpoint = honeycombOptions.Endpoint; | ||
o.TracesEndpoint = honeycombOptions.TracesEndpoint; | ||
o.MetricsEndpoint = honeycombOptions.MetricsEndpoint; | ||
o.SampleRate = honeycombOptions.SampleRate; | ||
o.ServiceName = honeycombOptions.ServiceName; | ||
o.ServiceVersion = honeycombOptions.ServiceVersion; | ||
o.InstrumentHttpClient = honeycombOptions.InstrumentHttpClient; | ||
o.InstrumentSqlClient = honeycombOptions.InstrumentSqlClient; | ||
o.InstrumentGrpcClient = honeycombOptions.InstrumentGrpcClient; | ||
o.InstrumentStackExchangeRedisClient = honeycombOptions.InstrumentStackExchangeRedisClient; | ||
o.MeterNames = honeycombOptions.MeterNames; | ||
}); | ||
} | ||
|
||
return builder; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Aguacongas.TheIdServer/Options/OpenTelemetry/ExporterOptions.cs
This file contains 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,14 @@ | ||
using Honeycomb.OpenTelemetry; | ||
using OpenTelemetry.Exporter; | ||
|
||
namespace Aguacongas.TheIdServer.Options.OpenTelemetry | ||
{ | ||
public class ExporterOptions | ||
{ | ||
public JaegerExporterOptions Jaeger { get; set; } | ||
public OtlpExporterOptions OpenTelemetryProtocol { get; set; } | ||
public ZipkinExporterOptions Zipkin { get; set; } | ||
|
||
public HoneycombOptions Honeycomb { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Aguacongas.TheIdServer/Options/OpenTelemetry/InstrumentationOptions.cs
This file contains 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,15 @@ | ||
using OpenTelemetry.Instrumentation.AspNetCore; | ||
using OpenTelemetry.Instrumentation.Http; | ||
using OpenTelemetry.Instrumentation.SqlClient; | ||
using OpenTelemetry.Instrumentation.StackExchangeRedis; | ||
|
||
namespace Aguacongas.TheIdServer.Options.OpenTelemetry | ||
{ | ||
public class InstrumentationOptions | ||
{ | ||
public AspNetCoreInstrumentationOptions AspNetCore{ get; set; } | ||
public HttpClientInstrumentationOptions HttpClient { get; set; } | ||
public SqlClientInstrumentationOptions SqlClient { get; set; } | ||
public RedisOptions Redis { get; set; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Aguacongas.TheIdServer/Options/OpenTelemetry/OpenTelemetryOptions.cs
This file contains 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,16 @@ | ||
| ||
|
||
namespace Aguacongas.TheIdServer.Options.OpenTelemetry | ||
{ | ||
public class OpenTelemetryOptions | ||
{ | ||
public ServiceOptions Service { get; set; } | ||
public bool ConsoleEnabled { get; set; } | ||
|
||
|
||
|
||
public InstrumentationOptions Instrumentation { get; set; } | ||
|
||
public ExporterOptions Exporter { get; set; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Aguacongas.TheIdServer/Options/OpenTelemetry/RedisOptions.cs
This file contains 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 @@ | ||
using OpenTelemetry.Instrumentation.StackExchangeRedis; | ||
|
||
namespace Aguacongas.TheIdServer.Options.OpenTelemetry | ||
{ | ||
public class RedisOptions : StackExchangeRedisCallsInstrumentationOptions | ||
{ | ||
public string ConnectionString { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Aguacongas.TheIdServer/Options/OpenTelemetry/ServiceOptions.cs
This file contains 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,11 @@ | ||
namespace Aguacongas.TheIdServer.Options.OpenTelemetry | ||
{ | ||
public class ServiceOptions | ||
{ | ||
public string Name { get; set; } | ||
public string Namespace { get; set; } | ||
public string Version { get; set; } | ||
public bool AutoGenerateServiceInstanceId { get; set; } = true; | ||
public string InstanceId { get; set; } | ||
} | ||
} |
Oops, something went wrong.