-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
d688900
commit dfc0741
Showing
7 changed files
with
98 additions
and
81 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
73 changes: 73 additions & 0 deletions
73
src/Services/Masa.Scheduler.Services.Worker/Extensions/OpenTelemetrySchedulerExtensions.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,73 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
using OpenTelemetry.Instrumentation.AspNetCore; | ||
using OpenTelemetry.Logs; | ||
using OpenTelemetry.Metrics; | ||
using OpenTelemetry.Resources; | ||
using OpenTelemetry.Trace; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
public static class OpenTelemetrySchedulerExtensions | ||
{ | ||
public static IServiceCollection AddSchedulerObservable(this IServiceCollection services, | ||
ILoggingBuilder loggingBuilder, | ||
Func<MasaObservableOptions> optionsConfigure, | ||
Func<string>? otlpUrlConfigure = null) | ||
{ | ||
var options = optionsConfigure(); | ||
var otlpUrl = otlpUrlConfigure?.Invoke() ?? string.Empty; | ||
|
||
ArgumentNullException.ThrowIfNull(options); | ||
|
||
Uri? uri = null; | ||
if (!string.IsNullOrEmpty(otlpUrl) && !Uri.TryCreate(otlpUrl, UriKind.Absolute, out uri)) | ||
throw new UriFormatException($"{nameof(otlpUrl)}:{otlpUrl} is invalid url"); | ||
|
||
var resources = ResourceBuilder.CreateDefault().AddMasaService(options); | ||
loggingBuilder.AddMasaOpenTelemetry(builder => | ||
{ | ||
builder.SetResourceBuilder(resources); | ||
builder.AddOtlpExporter(otlp => otlp.Endpoint = uri); | ||
}); | ||
|
||
services.AddMasaMetrics(builder => | ||
{ | ||
builder.SetResourceBuilder(resources); | ||
builder.AddOtlpExporter(options => | ||
{ | ||
options.Endpoint = uri; | ||
}); | ||
}); | ||
|
||
services.AddMasaTracing( | ||
builder => | ||
{ | ||
builder.SetResourceBuilder(resources); | ||
builder.AddOtlpExporter(options => options.Endpoint = uri); | ||
builder.AddSource("Masa.Scheduler.Background"); | ||
}, | ||
builder => | ||
{ | ||
builder.AspNetCoreInstrumentationOptions.AppendDefaultFilter(builder, false); | ||
builder.AspNetCoreInstrumentationOptions.AppendSchedulerFilter(builder); | ||
}); | ||
|
||
return services; | ||
} | ||
|
||
public static void AppendSchedulerFilter(this Action<AspNetCoreInstrumentationOptions> options, | ||
OpenTelemetryInstrumentationOptions openTelemetryInstrumentationOptions) | ||
{ | ||
options += opt => | ||
{ | ||
opt.Filter = (HttpContext httpContext) => | ||
{ | ||
var url = httpContext.Request.Path.Value ?? "/"; | ||
return !(url == "/" || url.Contains("/heartbeat")); | ||
}; | ||
}; | ||
openTelemetryInstrumentationOptions.AspNetCoreInstrumentationOptions += options; | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
.../Masa.Scheduler.Services.Worker/Extensions/TracingAop/HttpClientTracingInterceptorBase.cs
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...ces/Masa.Scheduler.Services.Worker/Extensions/TracingAop/IHttpClientTracingInterceptor.cs
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
.../Masa.Scheduler.Services.Worker/Extensions/TracingAop/TaskHttpClientTracingInterceptor.cs
This file was deleted.
Oops, something went wrong.
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