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

Resource allocation improvement #1463

Merged
merged 15 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from 12 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
12 changes: 6 additions & 6 deletions .github/workflows/dotnet-core-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ jobs:
- name: Setup .NET Core 2.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.807
dotnet-version: 2.1.811
Copy link
Member Author

Choose a reason for hiding this comment

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

I was getting an error that 2.1.807 could not be found. Bumped to latest.

Copy link
Contributor

Choose a reason for hiding this comment

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

we could change to 2.1.x and 3.1.x and remove the rsync script.

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up getting a conflict on the .net5 PR so while I was in there merging I switched to the ".x" for 2.1 & 3.1 versions.


- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
dotnet-version: 3.1.403

# For linux, we have to apply a workaround to enable both dotnet versions at same time
- name: .net SxS
run: |
rsync -a ${DOTNET_ROOT/3.1.301/2.1.807}/* $DOTNET_ROOT/
# For linux, we have to apply a workaround to enable both dotnet versions at same time
- name: .net SxS
run: |
rsync -a ${DOTNET_ROOT/3.1.403/2.1.811}/* $DOTNET_ROOT/

- name: Install dependencies
run: dotnet restore
Expand Down
2 changes: 2 additions & 0 deletions build/Common.prod.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<ItemGroup>
<AdditionalFiles Include=".publicApi\$(TargetFramework)\PublicAPI.Shipped.txt" />
<AdditionalFiles Include=".publicApi\$(TargetFramework)\PublicAPI.Unshipped.txt" />
<None Include=".publicApi\*\PublicAPI.Shipped.txt" />
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved
<None Include=".publicApi\*\PublicAPI.Unshipped.txt" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ OpenTelemetry.Baggage.RemoveBaggage(string name) -> OpenTelemetry.Baggage
OpenTelemetry.Baggage.SetBaggage(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> baggageItems) -> OpenTelemetry.Baggage
OpenTelemetry.Baggage.SetBaggage(params System.Collections.Generic.KeyValuePair<string, string>[] baggageItems) -> OpenTelemetry.Baggage
OpenTelemetry.Baggage.SetBaggage(string name, string value) -> OpenTelemetry.Baggage
OpenTelemetry.BaseProvider
OpenTelemetry.BaseProvider.BaseProvider() -> void
OpenTelemetry.BaseProvider.Dispose() -> void
OpenTelemetry.BaseProvider.~BaseProvider() -> void
OpenTelemetry.Context.Propagation.B3Propagator
OpenTelemetry.Context.Propagation.B3Propagator.B3Propagator() -> void
OpenTelemetry.Context.Propagation.B3Propagator.B3Propagator(bool singleHeader) -> void
Expand Down Expand Up @@ -70,7 +74,6 @@ OpenTelemetry.Metrics.Meter.Meter() -> void
OpenTelemetry.Metrics.MeterFactoryBase
OpenTelemetry.Metrics.MeterFactoryBase.MeterFactoryBase() -> void
OpenTelemetry.Metrics.MeterProvider
OpenTelemetry.Metrics.MeterProvider.Dispose() -> void
OpenTelemetry.Metrics.MeterProvider.MeterProvider() -> void
OpenTelemetry.Metrics.NoopBoundCounterMetric<T>
OpenTelemetry.Metrics.NoopBoundCounterMetric<T>.NoopBoundCounterMetric() -> void
Expand Down Expand Up @@ -166,7 +169,6 @@ OpenTelemetry.Trace.Tracer.StartRootSpan(string name, OpenTelemetry.Trace.SpanKi
OpenTelemetry.Trace.Tracer.StartSpan(string name, OpenTelemetry.Trace.SpanKind kind = OpenTelemetry.Trace.SpanKind.Internal, in OpenTelemetry.Trace.SpanContext parentContext = default(OpenTelemetry.Trace.SpanContext), OpenTelemetry.Trace.SpanAttributes initialAttributes = null, System.Collections.Generic.IEnumerable<OpenTelemetry.Trace.Link> links = null, System.DateTimeOffset startTime = default(System.DateTimeOffset)) -> OpenTelemetry.Trace.TelemetrySpan
OpenTelemetry.Trace.Tracer.StartSpan(string name, OpenTelemetry.Trace.SpanKind kind, in OpenTelemetry.Trace.TelemetrySpan parentSpan, OpenTelemetry.Trace.SpanAttributes initialAttributes = null, System.Collections.Generic.IEnumerable<OpenTelemetry.Trace.Link> links = null, System.DateTimeOffset startTime = default(System.DateTimeOffset)) -> OpenTelemetry.Trace.TelemetrySpan
OpenTelemetry.Trace.TracerProvider
OpenTelemetry.Trace.TracerProvider.Dispose() -> void
OpenTelemetry.Trace.TracerProvider.GetTracer(string name, string version = null) -> OpenTelemetry.Trace.Tracer
OpenTelemetry.Trace.TracerProvider.TracerProvider() -> void
abstract OpenTelemetry.Context.RuntimeContextSlot<T>.Get() -> T
Expand Down Expand Up @@ -300,10 +302,9 @@ static readonly OpenTelemetry.Metrics.NoopMeasureMetric<T>.Instance -> OpenTelem
static readonly OpenTelemetry.Trace.Status.Error -> OpenTelemetry.Trace.Status
static readonly OpenTelemetry.Trace.Status.Ok -> OpenTelemetry.Trace.Status
static readonly OpenTelemetry.Trace.Status.Unset -> OpenTelemetry.Trace.Status
virtual OpenTelemetry.BaseProvider.Dispose(bool disposing) -> void
virtual OpenTelemetry.Context.RuntimeContextSlot<T>.Dispose(bool disposing) -> void
virtual OpenTelemetry.Metrics.LabelSet.Labels.get -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>>
virtual OpenTelemetry.Metrics.LabelSet.Labels.set -> void
virtual OpenTelemetry.Metrics.MeterFactoryBase.GetMeter(string name, string version = null) -> OpenTelemetry.Metrics.Meter
virtual OpenTelemetry.Metrics.MeterProvider.Dispose(bool disposing) -> void
virtual OpenTelemetry.Metrics.MeterProvider.GetMeter(string name, string version = null) -> OpenTelemetry.Metrics.Meter
virtual OpenTelemetry.Trace.TracerProvider.Dispose(bool disposing) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ OpenTelemetry.Baggage.RemoveBaggage(string name) -> OpenTelemetry.Baggage
OpenTelemetry.Baggage.SetBaggage(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> baggageItems) -> OpenTelemetry.Baggage
OpenTelemetry.Baggage.SetBaggage(params System.Collections.Generic.KeyValuePair<string, string>[] baggageItems) -> OpenTelemetry.Baggage
OpenTelemetry.Baggage.SetBaggage(string name, string value) -> OpenTelemetry.Baggage
OpenTelemetry.BaseProvider
OpenTelemetry.BaseProvider.BaseProvider() -> void
OpenTelemetry.BaseProvider.Dispose() -> void
OpenTelemetry.BaseProvider.~BaseProvider() -> void
OpenTelemetry.Context.AsyncLocalRuntimeContextSlot<T>
OpenTelemetry.Context.AsyncLocalRuntimeContextSlot<T>.AsyncLocalRuntimeContextSlot(string name) -> void
OpenTelemetry.Context.Propagation.B3Propagator
Expand Down Expand Up @@ -70,7 +74,6 @@ OpenTelemetry.Metrics.Meter.Meter() -> void
OpenTelemetry.Metrics.MeterFactoryBase
OpenTelemetry.Metrics.MeterFactoryBase.MeterFactoryBase() -> void
OpenTelemetry.Metrics.MeterProvider
OpenTelemetry.Metrics.MeterProvider.Dispose() -> void
OpenTelemetry.Metrics.MeterProvider.MeterProvider() -> void
OpenTelemetry.Metrics.NoopBoundCounterMetric<T>
OpenTelemetry.Metrics.NoopBoundCounterMetric<T>.NoopBoundCounterMetric() -> void
Expand Down Expand Up @@ -166,7 +169,6 @@ OpenTelemetry.Trace.Tracer.StartRootSpan(string name, OpenTelemetry.Trace.SpanKi
OpenTelemetry.Trace.Tracer.StartSpan(string name, OpenTelemetry.Trace.SpanKind kind = OpenTelemetry.Trace.SpanKind.Internal, in OpenTelemetry.Trace.SpanContext parentContext = default(OpenTelemetry.Trace.SpanContext), OpenTelemetry.Trace.SpanAttributes initialAttributes = null, System.Collections.Generic.IEnumerable<OpenTelemetry.Trace.Link> links = null, System.DateTimeOffset startTime = default(System.DateTimeOffset)) -> OpenTelemetry.Trace.TelemetrySpan
OpenTelemetry.Trace.Tracer.StartSpan(string name, OpenTelemetry.Trace.SpanKind kind, in OpenTelemetry.Trace.TelemetrySpan parentSpan, OpenTelemetry.Trace.SpanAttributes initialAttributes = null, System.Collections.Generic.IEnumerable<OpenTelemetry.Trace.Link> links = null, System.DateTimeOffset startTime = default(System.DateTimeOffset)) -> OpenTelemetry.Trace.TelemetrySpan
OpenTelemetry.Trace.TracerProvider
OpenTelemetry.Trace.TracerProvider.Dispose() -> void
OpenTelemetry.Trace.TracerProvider.GetTracer(string name, string version = null) -> OpenTelemetry.Trace.Tracer
OpenTelemetry.Trace.TracerProvider.TracerProvider() -> void
abstract OpenTelemetry.Context.RuntimeContextSlot<T>.Get() -> T
Expand Down Expand Up @@ -300,10 +302,9 @@ static readonly OpenTelemetry.Metrics.NoopMeasureMetric<T>.Instance -> OpenTelem
static readonly OpenTelemetry.Trace.Status.Error -> OpenTelemetry.Trace.Status
static readonly OpenTelemetry.Trace.Status.Ok -> OpenTelemetry.Trace.Status
static readonly OpenTelemetry.Trace.Status.Unset -> OpenTelemetry.Trace.Status
virtual OpenTelemetry.BaseProvider.Dispose(bool disposing) -> void
virtual OpenTelemetry.Context.RuntimeContextSlot<T>.Dispose(bool disposing) -> void
virtual OpenTelemetry.Metrics.LabelSet.Labels.get -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>>
virtual OpenTelemetry.Metrics.LabelSet.Labels.set -> void
virtual OpenTelemetry.Metrics.MeterFactoryBase.GetMeter(string name, string version = null) -> OpenTelemetry.Metrics.Meter
virtual OpenTelemetry.Metrics.MeterProvider.Dispose(bool disposing) -> void
virtual OpenTelemetry.Metrics.MeterProvider.GetMeter(string name, string version = null) -> OpenTelemetry.Metrics.Meter
virtual OpenTelemetry.Trace.TracerProvider.Dispose(bool disposing) -> void
49 changes: 49 additions & 0 deletions src/OpenTelemetry.Api/BaseProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// <copyright file="BaseProvider.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;

namespace OpenTelemetry
{
/// <summary>
/// Contains logic shared by all OpenTelemetry providers.
/// </summary>
public abstract class BaseProvider : IDisposable
{
/// <summary>
/// Finalizes an instance of the <see cref="BaseProvider"/> class.
/// </summary>
~BaseProvider()
{
this.Dispose(false);
}

/// <inheritdoc/>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases the unmanaged resources used by this class and optionally releases the managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
}
}
}
17 changes: 1 addition & 16 deletions src/OpenTelemetry.Api/Metrics/MeterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OpenTelemetry.Metrics
/// <summary>
/// MeterProvider is the entry point of the OpenTelemetry Metrics API. It provides access to Meters.
/// </summary>
public class MeterProvider : IDisposable
public class MeterProvider : BaseProvider
{
private static ProxyMeter proxyMeter = new ProxyMeter();
private static bool isInitialized;
Expand Down Expand Up @@ -71,13 +71,6 @@ public static void SetDefault(MeterProvider meterProvider)
isInitialized = true;
}

/// <inheritdoc/>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Returns a Meter for a given name and version.
/// </summary>
Expand All @@ -96,13 +89,5 @@ internal static void Reset()
isInitialized = false;
defaultProvider = new MeterProvider();
}

/// <summary>
/// Releases the unmanaged resources used by this class and optionally releases the managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
}
}
}
18 changes: 1 addition & 17 deletions src/OpenTelemetry.Api/Trace/TracerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
// limitations under the License.
// </copyright>

using System;
using System.Diagnostics;

namespace OpenTelemetry.Trace
{
/// <summary>
/// TracerProvider is the entry point of the OpenTelemetry API. It provides access to <see cref="Tracer"/>.
/// </summary>
public class TracerProvider : IDisposable
public class TracerProvider : BaseProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="TracerProvider"/> class.
Expand Down Expand Up @@ -51,20 +50,5 @@ public Tracer GetTracer(string name, string version = null)

return new Tracer(new ActivitySource(name, version));
}

/// <inheritdoc/>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases the unmanaged resources used by this class and optionally releases the managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
}
}
}
3 changes: 1 addition & 2 deletions src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using OpenTelemetry.Logs;
#endif
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Exporter
{
Expand Down Expand Up @@ -99,7 +98,7 @@ public override ExportResult Export(in Batch<T> batch)
}
}

var resource = activity.GetResource();
var resource = this.ParentProvider.GetResource();
if (resource != Resource.Empty)
{
this.WriteLine("Resource associated with Activity:");
Expand Down
19 changes: 9 additions & 10 deletions src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using System.Runtime.CompilerServices;
using OpenTelemetry.Exporter.Jaeger.Implementation;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using Thrift.Protocol;
using Thrift.Transport;
using Process = OpenTelemetry.Exporter.Jaeger.Implementation.Process;
Expand Down Expand Up @@ -65,13 +64,13 @@ public override ExportResult Export(in Batch<Activity> activityBatch)
{
try
{
foreach (var activity in activityBatch)
if (this.processCache == null)
{
if (this.processCache == null)
{
this.ApplyLibraryResource(activity.GetResource());
}
this.SetResource(this.ParentProvider.GetResource());
}

foreach (var activity in activityBatch)
{
this.AppendSpan(activity.ToJaegerSpan());
}

Expand All @@ -87,18 +86,18 @@ public override ExportResult Export(in Batch<Activity> activityBatch)
}
}

internal void ApplyLibraryResource(Resource libraryResource)
internal void SetResource(Resource resource)
{
if (libraryResource is null)
if (resource is null)
{
throw new ArgumentNullException(nameof(libraryResource));
throw new ArgumentNullException(nameof(resource));
}

var process = this.Process;

string serviceName = null;
string serviceNamespace = null;
foreach (var label in libraryResource.Attributes)
foreach (var label in resource.Attributes)
{
string key = label.Key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using OpenTelemetry.Trace;
using OtlpCollector = Opentelemetry.Proto.Collector.Trace.V1;
using OtlpCommon = Opentelemetry.Proto.Common.V1;
using OtlpResource = Opentelemetry.Proto.Resource.V1;
using OtlpTrace = Opentelemetry.Proto.Trace.V1;

namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
Expand All @@ -40,23 +41,18 @@ internal static class ActivityExtensions

internal static void AddBatch(
this OtlpCollector.ExportTraceServiceRequest request,
OtlpExporter otlpExporter,
OtlpResource.Resource processResource,
in Batch<Activity> activityBatch)
{
Dictionary<string, OtlpTrace.InstrumentationLibrarySpans> spansByLibrary = new Dictionary<string, OtlpTrace.InstrumentationLibrarySpans>();
OtlpTrace.ResourceSpans resourceSpans = null;
OtlpTrace.ResourceSpans resourceSpans = new OtlpTrace.ResourceSpans
{
Resource = processResource,
};
request.ResourceSpans.Add(resourceSpans);

foreach (var activity in activityBatch)
{
if (resourceSpans == null)
{
resourceSpans = new OtlpTrace.ResourceSpans
{
Resource = otlpExporter.EnsureProcessResource(activity),
};
request.ResourceSpans.Add(resourceSpans);
}

OtlpTrace.Span span = activity.ToOtlpSpan();
if (span == null)
{
Expand Down
Loading