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

Add telemetry.sdk.* attributes to default resource #4369

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/OpenTelemetry/Resources/ResourceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ private ResourceBuilder()
/// </summary>
/// <returns>Created <see cref="ResourceBuilder"/>.</returns>
public static ResourceBuilder CreateDefault()
alanwest marked this conversation as resolved.
Show resolved Hide resolved
=> new ResourceBuilder().AddResource(DefaultResource).AddEnvironmentVariableDetector();
=> new ResourceBuilder()
.AddResource(DefaultResource)
.AddTelemetrySdk()
.AddEnvironmentVariableDetector();

/// <summary>
/// Creates an empty <see cref="ResourceBuilder"/> instance.
Expand Down
22 changes: 15 additions & 7 deletions test/OpenTelemetry.Tests/Resources/ResourceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ public void GetResourceWithTelemetrySDKAttributes()
// Assert
var attributes = resource.Attributes;
Assert.Equal(4, attributes.Count());
ValidateDefaultAttributes(attributes);
ValidateTelemetrySdkAttributes(attributes);
}

Expand All @@ -406,8 +407,9 @@ public void GetResourceWithDefaultAttributes_EmptyResource()

// Assert
var attributes = resource.Attributes;
Assert.Single(attributes);
Assert.Equal(4, attributes.Count());
ValidateDefaultAttributes(attributes);
ValidateTelemetrySdkAttributes(attributes);
}

[Fact]
Expand All @@ -418,9 +420,10 @@ public void GetResourceWithDefaultAttributes_ResourceWithAttrs()

// Assert
var attributes = resource.Attributes;
Assert.Equal(3, attributes.Count());
Assert.Equal(6, attributes.Count());
ValidateAttributes(attributes, 0, 1);
ValidateDefaultAttributes(attributes);
ValidateTelemetrySdkAttributes(attributes);
}

[Fact]
Expand All @@ -432,11 +435,12 @@ public void GetResourceWithDefaultAttributes_WithResourceEnvVar()

// Assert
var attributes = resource.Attributes;
Assert.Equal(5, attributes.Count());
Assert.Equal(8, attributes.Count());
ValidateAttributes(attributes, 0, 1);
ValidateDefaultAttributes(attributes);
Assert.Contains(new KeyValuePair<string, object>("EVKey1", "EVVal1"), attributes);
Assert.Contains(new KeyValuePair<string, object>("EVKey2", "EVVal2"), attributes);
ValidateTelemetrySdkAttributes(attributes);
}

[Fact]
Expand All @@ -448,9 +452,10 @@ public void EnvironmentVariableDetectors_DoNotDuplicateAttributes()

// Assert
var attributes = resource.Attributes;
Assert.Equal(3, attributes.Count());
Assert.Equal(6, attributes.Count());
Assert.Contains(new KeyValuePair<string, object>("EVKey1", "EVVal1"), attributes);
Assert.Contains(new KeyValuePair<string, object>("EVKey2", "EVVal2"), attributes);
ValidateTelemetrySdkAttributes(attributes);
}

[Fact]
Expand All @@ -462,9 +467,10 @@ public void GetResource_WithServiceEnvVar()

// Assert
var attributes = resource.Attributes;
Assert.Equal(3, attributes.Count());
Assert.Equal(6, attributes.Count());
ValidateAttributes(attributes, 0, 1);
Assert.Contains(new KeyValuePair<string, object>("service.name", "some-service"), attributes);
ValidateTelemetrySdkAttributes(attributes);
}

[Fact]
Expand All @@ -477,9 +483,10 @@ public void GetResource_WithServiceNameSetWithTwoEnvVars()

// Assert
var attributes = resource.Attributes;
Assert.Equal(3, attributes.Count());
Assert.Equal(6, attributes.Count());
ValidateAttributes(attributes, 0, 1);
Assert.Contains(new KeyValuePair<string, object>("service.name", "from-service-name"), attributes);
ValidateTelemetrySdkAttributes(attributes);
}

[Fact]
Expand All @@ -492,9 +499,10 @@ public void GetResource_WithServiceNameSetWithTwoEnvVarsAndCode()

// Assert
var attributes = resource.Attributes;
Assert.Equal(4, attributes.Count());
Assert.Equal(7, attributes.Count());
ValidateAttributes(attributes, 0, 1);
Assert.Contains(new KeyValuePair<string, object>("service.name", "from-code"), attributes);
ValidateTelemetrySdkAttributes(attributes);
}

[Fact]
Expand Down