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

Remove Resource public ctor as Provider expects ResourceBuilder now #1566

Merged
merged 6 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ OpenTelemetry.ProviderExtensions
OpenTelemetry.Resources.Resource
OpenTelemetry.Resources.Resource.Attributes.get -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>
OpenTelemetry.Resources.Resource.Merge(OpenTelemetry.Resources.Resource other) -> OpenTelemetry.Resources.Resource
OpenTelemetry.Resources.Resource.Resource(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) -> void
OpenTelemetry.Resources.ResourceBuilder
OpenTelemetry.Resources.ResourceBuilder.AddResource(OpenTelemetry.Resources.Resource resource) -> OpenTelemetry.Resources.ResourceBuilder
OpenTelemetry.Resources.ResourceBuilder.Build() -> OpenTelemetry.Resources.Resource
Expand Down
1 change: 0 additions & 1 deletion src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ OpenTelemetry.ProviderExtensions
OpenTelemetry.Resources.Resource
OpenTelemetry.Resources.Resource.Attributes.get -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>
OpenTelemetry.Resources.Resource.Merge(OpenTelemetry.Resources.Resource other) -> OpenTelemetry.Resources.Resource
OpenTelemetry.Resources.Resource.Resource(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) -> void
OpenTelemetry.Resources.ResourceBuilder
OpenTelemetry.Resources.ResourceBuilder.AddResource(OpenTelemetry.Resources.Resource resource) -> OpenTelemetry.Resources.ResourceBuilder
OpenTelemetry.Resources.ResourceBuilder.Build() -> OpenTelemetry.Resources.Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ OpenTelemetry.ProviderExtensions
OpenTelemetry.Resources.Resource
OpenTelemetry.Resources.Resource.Attributes.get -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>
OpenTelemetry.Resources.Resource.Merge(OpenTelemetry.Resources.Resource other) -> OpenTelemetry.Resources.Resource
OpenTelemetry.Resources.Resource.Resource(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) -> void
OpenTelemetry.Resources.ResourceBuilder
OpenTelemetry.Resources.ResourceBuilder.AddResource(OpenTelemetry.Resources.Resource resource) -> OpenTelemetry.Resources.ResourceBuilder
OpenTelemetry.Resources.ResourceBuilder.Build() -> OpenTelemetry.Resources.Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ OpenTelemetry.ProviderExtensions
OpenTelemetry.Resources.Resource
OpenTelemetry.Resources.Resource.Attributes.get -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>
OpenTelemetry.Resources.Resource.Merge(OpenTelemetry.Resources.Resource other) -> OpenTelemetry.Resources.Resource
OpenTelemetry.Resources.Resource.Resource(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) -> void
OpenTelemetry.Resources.ResourceBuilder
OpenTelemetry.Resources.ResourceBuilder.AddResource(OpenTelemetry.Resources.Resource resource) -> OpenTelemetry.Resources.ResourceBuilder
OpenTelemetry.Resources.ResourceBuilder.Build() -> OpenTelemetry.Resources.Resource
Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
* `telemetry.sdk.name` = `opentelemetry`
* `telemetry.sdk.language` = `dotnet`
* `telemetry.sdk.version` = [SDK version]
* `Resource` constructor marked as internal, as `ResourceBuilder` is
the recommended API to build resources.
([#1566](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1566))

## 0.8.0-beta.1

Expand Down
7 changes: 4 additions & 3 deletions src/OpenTelemetry/Resources/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ namespace OpenTelemetry.Resources
{
/// <summary>
/// <see cref="Resource"/> represents a resource, which captures identifying information about the entities
/// for which signals (stats or traces) are reported.
/// for which telemetry is reported.
/// Use <see cref="ResourceBuilder"/> to construct resource instances.
/// </summary>
public class Resource
{
// this implementation follows https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/resource/sdk.md
// This implementation follows https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/resource/sdk.md

/// <summary>
/// Initializes a new instance of the <see cref="Resource"/> class.
/// </summary>
/// <param name="attributes">An <see cref="IEnumerable{T}"/> of attributes that describe the resource.</param>
public Resource(IEnumerable<KeyValuePair<string, object>> attributes)
internal Resource(IEnumerable<KeyValuePair<string, object>> attributes)
{
if (attributes == null)
{
Expand Down
5 changes: 3 additions & 2 deletions src/OpenTelemetry/Trace/TracerProviderBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ public static TracerProviderBuilder SetSampler(this TracerProviderBuilder tracer
}

/// <summary>
/// Sets the <see cref="Resource"/> describing the app associated with all traces. Overwrites currently set resource.
/// Sets the <see cref="ResourceBuilder"/> from which the Resource associated with
/// this provider is built from. Overwrites currently set ResourceBuilder.
/// </summary>
/// <param name="tracerProviderBuilder">TracerProviderBuilder instance.</param>
/// <param name="resourceBuilder"><see cref="ResourceBuilder"/> to be associate with all traces.</param>
/// <param name="resourceBuilder"><see cref="ResourceBuilder"/> from which Resource will be built.</param>
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
public static TracerProviderBuilder SetResourceBuilder(this TracerProviderBuilder tracerProviderBuilder, ResourceBuilder resourceBuilder)
{
Expand Down
5 changes: 3 additions & 2 deletions src/OpenTelemetry/Trace/TracerProviderBuilderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ internal TracerProviderBuilder SetSampler(Sampler sampler)
}

/// <summary>
/// Sets the <see cref="Resource"/> describing the app associated with all traces. Overwrites currently set resource.
/// Sets the <see cref="ResourceBuilder"/> from which the Resource associated with
/// this provider is built from. Overwrites currently set ResourceBuilder.
/// </summary>
/// <param name="resourceBuilder"><see cref="ResourceBuilder"/> to be associate with all traces.</param>
/// <param name="resourceBuilder"><see cref="ResourceBuilder"/> from which Resource will be built.</param>
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
internal TracerProviderBuilder SetResourceBuilder(ResourceBuilder resourceBuilder)
{
Expand Down
12 changes: 6 additions & 6 deletions test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public void JaegerTraceExporter_SetResource_CreatesTags()
using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions());
var process = jaegerTraceExporter.Process;

jaegerTraceExporter.SetResource(new Resource(new Dictionary<string, object>
jaegerTraceExporter.SetResource(ResourceBuilder.CreateEmpty().AddAttributes(new Dictionary<string, object>
{
["Tag"] = "value",
}));
}).Build());

Assert.NotNull(process.Tags);
Assert.Single(process.Tags);
Expand All @@ -90,10 +90,10 @@ public void JaegerTraceExporter_SetResource_CombinesTags()

process.Tags = new Dictionary<string, JaegerTag> { ["Tag1"] = new KeyValuePair<string, object>("Tag1", "value1").ToJaegerTag() };

jaegerTraceExporter.SetResource(new Resource(new Dictionary<string, object>
jaegerTraceExporter.SetResource(ResourceBuilder.CreateEmpty().AddAttributes(new Dictionary<string, object>
{
["Tag2"] = "value2",
}));
}).Build());

Assert.NotNull(process.Tags);
Assert.Equal(2, process.Tags.Count);
Expand All @@ -107,11 +107,11 @@ public void JaegerTraceExporter_SetResource_IgnoreServiceResources()
using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions());
var process = jaegerTraceExporter.Process;

jaegerTraceExporter.SetResource(new Resource(new Dictionary<string, object>
jaegerTraceExporter.SetResource(ResourceBuilder.CreateEmpty().AddAttributes(new Dictionary<string, object>
{
[ResourceSemanticConventions.AttributeServiceName] = "servicename",
[ResourceSemanticConventions.AttributeServiceNamespace] = "servicenamespace",
}));
}).Build());

Assert.Null(process.Tags);
}
Expand Down