Skip to content

Commit

Permalink
[Continuous Profiling] Set InstrumentationScope (#3928)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Jan 14, 2025
1 parent 56ed0e8 commit 89883dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/IntegrationTests/ContinuousProfilerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#if NET

using FluentAssertions;
using IntegrationTests.Helpers;
using OpenTelemetry.Proto.Collector.Profiles.V1Development;
using OpenTelemetry.Proto.Profiles.V1Development;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void ExportThreadSamples()
SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "TestApplication.ContinuousProfiler");
var expectedStackTrace = string.Join("\n", CreateExpectedStackTrace());

collector.ExpectCollected(AllLocationReferencesProfileFrameTypeAttribute, "All location should contain reference to profile.frame.type attribute");
collector.ExpectCollected(ExpectCollected, "Expect Collected failed");
collector.Expect(profileData => profileData.ResourceProfiles.Any(resourceProfiles => resourceProfiles.ScopeProfiles.Any(scopeProfile => scopeProfile.Profiles.Any(profile => ContainStackTraceForClassHierarchy(profile, expectedStackTrace) && ContainAttributes(profile, "cpu")))));
collector.ResourceExpector.Expect("todo.resource.detector.key", "todo.resource.detector.value");

Expand All @@ -57,11 +58,14 @@ public void ExportThreadSamples()
collector.ResourceExpector.AssertExpectations();
}

private static bool AllLocationReferencesProfileFrameTypeAttribute(ICollection<ExportProfilesServiceRequest> c)
private static bool ExpectCollected(ICollection<ExportProfilesServiceRequest> c)
{
var profiles = c.SelectMany(r => r.ResourceProfiles)
.SelectMany(rp => rp.ScopeProfiles)
.SelectMany(sp => sp.Profiles).ToList();
var scopeProfiles = c.SelectMany(r => r.ResourceProfiles)
.SelectMany(rp => rp.ScopeProfiles).ToList();

scopeProfiles.Should().AllSatisfy(sp => sp.Scope.Name.Should().Be("OpenTelemetry.AutoInstrumentation"));

var profiles = scopeProfiles.SelectMany(sp => sp.Profiles).ToList();

foreach (var profile in profiles)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ private static ResourceProfiles CreateResourceProfiles(ScopeProfiles scopeProfil
private static ScopeProfiles CreateScopeProfiles()
{
var scopeProfiles = new ScopeProfiles();
scopeProfiles.Scope = new InstrumentationScope
{
Name = "OpenTelemetry.AutoInstrumentation",
// TODO consider setting Version here
};

// TODO handle schema Url scopeProfiles.SchemaUrl

return scopeProfiles;
Expand Down

0 comments on commit 89883dd

Please sign in to comment.