-
Notifications
You must be signed in to change notification settings - Fork 140
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
Add manual+automatic instrumentation tests + fix SetUser
bug
#4938
Merged
andrewlock
merged 4 commits into
master
from
andrew/add-manual-instrumentation-integration-test
Dec 1, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// <copyright file="AspNetCoreAvailabilityChecker.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
#if !NETFRAMEWORK | ||
|
||
using System; | ||
|
||
namespace Datadog.Trace; | ||
|
||
internal static class AspNetCoreAvailabilityChecker | ||
{ | ||
private static readonly Lazy<bool> IsAvailable = new(CheckForRequiredTypes); | ||
|
||
private static bool CheckForRequiredTypes() | ||
{ | ||
try | ||
{ | ||
// Try to load the HttpContext type | ||
// Assumes that this is only called when we would expect the type to | ||
// already be loaded, for example inside an ASP.NET Core request. | ||
// As this is only checked _once_, it assumes the customer doesn't call | ||
// this API both _before_ ASP.NET Core types are loaded _and_ afterwards. | ||
var httpContextType = Type.GetType("Microsoft.AspNetCore.Http.HttpContext, Microsoft.AspNetCore.Http.Abstractions", throwOnError: false); | ||
return httpContextType is not null; | ||
} | ||
catch | ||
{ | ||
// Problem loading the type, so assume we're not in aspnetcore | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Should be called when ASP.NET Core is expected to be loaded, | ||
/// and checks if ASP.NET Core types are available | ||
/// </summary> | ||
public static bool IsAspNetCoreAvailable() => IsAvailable.Value; | ||
} | ||
#endif |
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
60 changes: 60 additions & 0 deletions
60
tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/ManualInstrumentationTests.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,60 @@ | ||
// <copyright file="ManualInstrumentationTests.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
using System.Threading.Tasks; | ||
using Datadog.Trace.TestHelpers; | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using VerifyXunit; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Datadog.Trace.ClrProfiler.IntegrationTests; | ||
|
||
[UsesVerify] | ||
public class ManualInstrumentationTests : TestHelper | ||
{ | ||
public ManualInstrumentationTests(ITestOutputHelper output) | ||
: base("ManualInstrumentation", output) | ||
{ | ||
} | ||
|
||
[SkippableFact] | ||
[Trait("RunOnWindows", "True")] | ||
public async Task ManualAndAutomatic() | ||
{ | ||
const int expectedSpans = 36; | ||
using var telemetry = this.ConfigureTelemetry(); | ||
using var agent = EnvironmentHelper.GetMockAgent(); | ||
using var assert = new AssertionScope(); | ||
using var process = RunSampleAndWaitForExit(agent); | ||
|
||
var spans = agent.WaitForSpans(expectedSpans); | ||
spans.Should().HaveCount(expectedSpans); | ||
|
||
var settings = VerifyHelper.GetSpanVerifierSettings(); | ||
|
||
await VerifyHelper.VerifySpans(spans, settings); | ||
} | ||
|
||
[SkippableFact] | ||
[Trait("RunOnWindows", "True")] | ||
public async Task ManualOnly() | ||
{ | ||
EnvironmentHelper.SetAutomaticInstrumentation(false); | ||
const int expectedSpans = 29; | ||
using var telemetry = this.ConfigureTelemetry(); | ||
using var agent = EnvironmentHelper.GetMockAgent(); | ||
using var assert = new AssertionScope(); | ||
using var process = RunSampleAndWaitForExit(agent); | ||
|
||
var spans = agent.WaitForSpans(expectedSpans); | ||
spans.Should().HaveCount(expectedSpans); | ||
|
||
var settings = VerifyHelper.GetSpanVerifierSettings(); | ||
|
||
await VerifyHelper.VerifySpans(spans, settings); | ||
} | ||
} |
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.
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.
Nice trick.