Skip to content
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

Merged
merged 33 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
831d712
use the same activity created by existing instrumentation. Simply enh…
cijothomas May 26, 2020
737f9b6
Merge branch 'master' into cijothomas/activity3adapter1a_alternate
cijothomas Jun 1, 2020
9b840f0
remove sampling from instrumentation
cijothomas Jun 2, 2020
036a9bb
Merge branch 'master' into cijothomas/activity3adapter1a_alternate
cijothomas Jun 2, 2020
5b836a4
Merge branch 'cijothomas/activity3adapter1a_alternate' of https://git…
cijothomas Jun 2, 2020
382d85f
Merge branch 'master' into cijothomas/activity3adapter1a_alternate
cijothomas Jun 2, 2020
f1e5108
add asp.net core instrumentation
cijothomas Jun 2, 2020
170ad87
Merge branch 'cijothomas/activity3adapter1a_alternate' of https://git…
cijothomas Jun 2, 2020
0832e71
Merge branch 'master' into cijothomas/activity3adapter1a_alternate
cijothomas Jun 2, 2020
3b4cbb7
Merge branch 'master' into cijothomas/activity3adapter1a_alternate
cijothomas Jun 2, 2020
19d138f
move sampling to Instrumentation for now.
cijothomas Jun 4, 2020
121e4b5
Merge branch 'master' into cijothomas/activity3adapter1a_alternate
cijothomas Jun 4, 2020
823fee6
Add httpClient .net core instrumentation
cijothomas Jun 4, 2020
c759d8a
Ad SqlClientInstrumentation
cijothomas Jun 4, 2020
6df93de
remove sqlclientinstrumentation from previous instrumentation
cijothomas Jun 4, 2020
0d07263
Quick implementation for AzureClients - not validated as there are un…
cijothomas Jun 5, 2020
692b0dc
fix examples
cijothomas Jun 5, 2020
7185426
Merge branch 'master' into cijothomas/activity3adapter1a_alternate
cijothomas Jun 5, 2020
37071c5
fix sampling flag
cijothomas Jun 8, 2020
b889a8c
Merge branch 'cijothomas/activity3adapter1a_alternate' of https://git…
cijothomas Jun 8, 2020
8630782
made sample app work with jaeger
cijothomas Jun 8, 2020
c4834ae
Mark todos and fix AspNet tests
cijothomas Jun 8, 2020
581cd1e
Fix asp.net core tests and mark TODOs
cijothomas Jun 8, 2020
7341c59
Add TODO for httpclient .net core test and fix test
cijothomas Jun 8, 2020
d9c9fff
add todo and fix httpclient test
cijothomas Jun 9, 2020
514d89c
add todos and fil sqlclienttests
cijothomas Jun 9, 2020
f939361
Make OpenTelemetrySDK disposable and take care of disposing all ds su…
cijothomas Jun 9, 2020
a220d9e
Added OpenTelemetry.Default instead of static method
cijothomas Jun 9, 2020
99b91bf
Merge branch 'master' into cijothomas/activity3adapter1a_alternate
cijothomas Jun 9, 2020
63dc16f
conflict resolve
cijothomas Jun 9, 2020
11a175a
AspNet, AspNetCore fix Dispose issue
cijothomas Jun 9, 2020
efdb1d3
conflict
cijothomas Jun 10, 2020
3646fa1
stylecop stuff lost i merge
cijothomas Jun 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/Exporters/Web/OpenTelemetry.Exporter.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\OpenTelemetry.Exporter.Console\OpenTelemetry.Exporter.Console.csproj" />
<ProjectReference Include="..\..\..\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" />
<ProjectReference Include="..\..\..\src\OpenTelemetry.Instrumentation.Dependencies\OpenTelemetry.Instrumentation.Dependencies.csproj" />
<ProjectReference Include="..\..\..\src\OpenTelemetry.Exporter.Zipkin\OpenTelemetry.Exporter.Zipkin.csproj" />
Copy link
Contributor

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.

Expand Down
5 changes: 5 additions & 0 deletions samples/Exporters/Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using OpenTelemetry.Exporter.Console;
using OpenTelemetry.Trace.Configuration;

namespace API
Expand Down Expand Up @@ -36,6 +37,10 @@ public void ConfigureServices(IServiceCollection services)
}
});

OpenTelemetrySdk.EnableOpenTelemetry(
(builder) => builder.AddActivitySource(string.Empty)
.UseConsoleActivityExporter(opt => opt.DisplayAsJson = opt.DisplayAsJson));

services.AddOpenTelemetry((sp, builder) =>
{
builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Microsoft.AspNetCore.Http.Features;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Trace;
using OpenTelemetry.Trace.Samplers;

namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
{
Expand All @@ -35,6 +36,7 @@ internal class HttpInListener : ListenerHandler
private readonly PropertyFetcher beforeActionTemplateFetcher = new PropertyFetcher("Template");
private readonly bool hostingSupportsW3C = false;
private readonly AspNetCoreInstrumentationOptions options;
private readonly ActivitySampler sampler = new AlwaysOnActivitySampler();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoded sampler for just prototyping.


public HttpInListener(string name, Tracer tracer, AspNetCoreInstrumentationOptions options)
: base(name, tracer)
Expand All @@ -60,10 +62,21 @@ public override void OnStartActivity(Activity activity, object payload)
return;
}

// TODO: the line below once .NET ships new Activity
// Or do reflection now.
// activity.ActivityKind = ActivityKind.Server

var request = context.Request;

// see the spec https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md
var path = (request.PathBase.HasValue || request.Path.HasValue) ? (request.PathBase + request.Path).ToString() : "/";
if (activity != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activity [](start = 16, length = 8)

is it possible the Activity can be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I didnt need the activity null check.

{
activity.DisplayName = path;
}

var samplingDecision = this.sampler.ShouldSample(activity.Context, activity.TraceId, default, path, activity.Kind, activity.Tags, activity.Links);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part which makes me not 100% convinved this approach is right. All instrumentationadatpers now need to know about Samplers (which is SDK concept).

Instead of simply checking if activity.IsAllDataRequested, its now first setting IsAllDataRequested by running sampling algorithm

activity.IsAllDataRequested = samplingDecision.IsSampled;

TelemetrySpan span;
if (this.hostingSupportsW3C && this.options.TextFormat is TraceContextFormat)
Expand All @@ -90,6 +103,25 @@ public override void OnStartActivity(Activity activity, object payload)
span.PutHttpUserAgentAttribute(userAgent);
span.PutHttpRawUrlAttribute(GetUri(request));
}

if (activity.IsAllDataRequested)
{
if (request.Host.Port == 80 || request.Host.Port == 443)
{
activity.AddTag("http.host", request.Host.Host);
}
else
{
activity.AddTag("http.host", request.Host.Host + ":" + request.Host.Port);
}

activity.AddTag("http.method", request.Method);
activity.AddTag("http.path", path);

var userAgent = request.Headers["User-Agent"].FirstOrDefault();
activity.AddTag("http.user_agent", userAgent);
activity.AddTag("http.url", GetUri(request));
}
}

public override void OnStopActivity(Activity activity, object payload)
Expand All @@ -114,6 +146,11 @@ public override void OnStopActivity(Activity activity, object payload)
var response = context.Response;

span.PutHttpStatusCode(response.StatusCode, response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase);

if (activity.IsAllDataRequested)
{
activity.AddTag("http.status_code", response.StatusCode.ToString());
}
}

span.End();
Expand Down