-
Notifications
You must be signed in to change notification settings - Fork 730
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
Instrumentation Adapters to support Activity API #701
Changes from 9 commits
831d712
737f9b6
9b840f0
036a9bb
5b836a4
382d85f
f1e5108
170ad87
0832e71
3b4cbb7
19d138f
121e4b5
823fee6
c759d8a
6df93de
0d07263
692b0dc
7185426
37071c5
b889a8c
8630782
c4834ae
581cd1e
7341c59
d9c9fff
514d89c
f939361
a220d9e
99b91bf
63dc16f
11a175a
efdb1d3
3646fa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// <copyright file="OpenTelemetryBuilderExtensions.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using OpenTelemetry.Instrumentation.AspNetCore; | ||
|
||
namespace OpenTelemetry.Trace.Configuration | ||
{ | ||
/// <summary> | ||
/// Extension methods to simplify registering of asp.net core request instrumentation. | ||
/// </summary> | ||
public static class OpenTelemetryBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Enables the incoming requests automatic data collection for Asp.Net Core. | ||
/// </summary> | ||
/// <param name="builder"><see cref="OpenTelemetryBuilder"/> being configured.</param> | ||
/// <param name="configureAspNetCoreInstrumentationOptions">ASP.NET Core Request configuration options.</param> | ||
/// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns> | ||
public static OpenTelemetryBuilder AddRequestInstrumentation( | ||
this OpenTelemetryBuilder builder, | ||
Action<AspNetCoreInstrumentationOptions> configureAspNetCoreInstrumentationOptions = null) | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
builder.AddActivitySource(string.Empty); | ||
var aspnetCoreOptions = new AspNetCoreInstrumentationOptions(); | ||
configureAspNetCoreInstrumentationOptions?.Invoke(aspnetCoreOptions); | ||
|
||
// TODO: decide who is responsible for dispose upon shutdown. | ||
new AspNetCoreInstrumentation(aspnetCoreOptions); | ||
|
||
return builder; | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OpenTelemetry.Internal; | ||
using OpenTelemetry.Trace.Samplers; | ||
|
||
namespace OpenTelemetry.Trace.Export | ||
{ | ||
|
@@ -27,6 +28,7 @@ namespace OpenTelemetry.Trace.Export | |
public class SimpleActivityProcessor : ActivityProcessor, IDisposable | ||
{ | ||
private readonly ActivityExporter exporter; | ||
private readonly ActivitySampler sampler = new AlwaysOnActivitySampler(); | ||
private bool disposed = false; | ||
|
||
/// <summary> | ||
|
@@ -41,6 +43,16 @@ public SimpleActivityProcessor(ActivityExporter exporter) | |
/// <inheritdoc /> | ||
public override void OnStart(Activity activity) | ||
{ | ||
// Perform sampling decision if source is empty. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not 100% correct, as the sampling decision is now made with the current ActivityKind (which would be Internal, the default value). Though none of the built-in Samplers makes use of ActivityKind, nothing prevents one from writing Sampler which takes Kind into consideration. More better would be to "feed" this activity created outside of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @CodeBlanch for proposing the idea of "feeding" an external activity to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you present the idea to .NET team? Any feedback? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CodeBlanch we (the .NET team) will look at that to decide what is the best way can achieve this scenario. Thanks for your feedback, it is really helpful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that making sampling decision in SDK piece is going to be incorrect (as we have incorrect Kind), I'll move the sampling logic into the InstrumentationAdapters. Of course this forces Instrumentation to have dependency on Sampling - but doing this to make progress and uncover any other potential issues. If everything else is good, and the only remaining issue is Instrumentation being aware of Samplers - we'll try to get a new API in activity source to run the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this to set the Kind? reflection can work here till we expose the Kind setter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't set the Kind to the correct one in the OT SDK as SDK doesn't know what is the actual kind. InstrumentationAdapter knows it, and it sets it. |
||
// This occurs for activities created outside of ActivitySource | ||
// i.e new Activity() directly. | ||
// Note: This also can occur if one creates an ActivitySource of the name string.empty. | ||
// In that case, the sampling logic would be run twice! | ||
if (activity.Source.Name.Equals(string.Empty)) | ||
cijothomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var samplingDecision = this.sampler.ShouldSample(activity.Context, activity.TraceId, default, activity.DisplayName, activity.Kind, activity.Tags, activity.Links); | ||
activity.IsAllDataRequested = samplingDecision.IsSampled; | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
|
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 will create the Activity exporter for Zipkin this week or the next.