Skip to content

Commit

Permalink
Merge branch 'main' into zipkin-exporter-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Jan 28, 2021
2 parents 5073862 + cc93a78 commit 1584a6a
Show file tree
Hide file tree
Showing 34 changed files with 212 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docfx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: docfx

on:
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-core-cov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Code Coverage

on:
push:
branches: [ master ]
branches: [ main ]
paths-ignore:
- '**.md'
pull_request:
branches: [ master ]
branches: [ main ]
paths-ignore:
- '**.md'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-core-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Linux

on:
pull_request:
branches: [ master ]
branches: [ main ]
paths-ignore:
- '**.md'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-core-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Windows

on:
pull_request:
branches: [ master ]
branches: [ main ]
paths-ignore:
- '**.md'

Expand All @@ -16,7 +16,7 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Setup .NET Core 2.1
uses: actions/setup-dotnet@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: dotnet format

on:
pull_request:
branches: [ master ]
branches: [ main ]
paths:
- '**.cs'
- '.editorconfig'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Integration Tests

on:
push:
branches: [ master ]
branches: [ main ]
paths-ignore:
- '**.md'
pull_request:
branches: [ master ]
branches: [ main ]
paths-ignore:
- '**.md'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/markdownlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: markdownlint

on:
pull_request:
branches: [ master ]
branches: [ main ]
paths:
- '**.md'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sanitycheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: sanitycheck

on:
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
misspell:
Expand Down
10 changes: 4 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,10 @@ issue](https://github.com/open-telemetry/opentelemetry-specification/issues/165)

## Style Guide

This project includes a
[`.editorconfig`](https://github.com/open-telemetry/opentelemetry-dotnet/blob/master/.editorconfig)
file which is supported by all the IDEs/editor mentioned above. It works with
the IDE/editor only and does not affect the actual build of the project.
This project includes a [`.editorconfig`](./.editorconfig) file which is
supported by all the IDEs/editor mentioned above. It works with the IDE/editor
only and does not affect the actual build of the project.

This repository also includes [stylecop ruleset
files](https://github.com/open-telemetry/opentelemetry-dotnet/tree/master/build).
This repository also includes stylecop ruleset files under the `./build` folder.
These files are used to configure the _StyleCop.Analyzers_ which runs during
build. Breaking the rules will result in a build failure.
5 changes: 3 additions & 2 deletions OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
NuGet.config = NuGet.config
OpenTelemetry.proj = OpenTelemetry.proj
README.md = README.md
RELEASING.md = RELEASING.md
tool_FinalizePublicApi.ps1 = tool_FinalizePublicApi.ps1
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7CB2F02E-03FA-4FFF-89A5-C51F107623FD}"
Expand All @@ -29,10 +27,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7CB2F02E
build\docfx.cmd = build\docfx.cmd
build\docker-compose.netcoreapp2.1.yml = build\docker-compose.netcoreapp2.1.yml
build\docker-compose.netcoreapp3.1.yml = build\docker-compose.netcoreapp3.1.yml
build\finalize-publicapi.ps1 = build\finalize-publicapi.ps1
build\opentelemetry-icon-color.png = build\opentelemetry-icon-color.png
build\OpenTelemetry.prod.loose.ruleset = build\OpenTelemetry.prod.loose.ruleset
build\OpenTelemetry.prod.ruleset = build\OpenTelemetry.prod.ruleset
build\OpenTelemetry.test.ruleset = build\OpenTelemetry.test.ruleset
build\process-codecoverage.ps1 = build\process-codecoverage.ps1
build\RELEASING.md = build\RELEASING.md
build\stylecop.json = build\stylecop.json
build\xunit.runner.json = build\xunit.runner.json
EndProjectSection
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tool_FinalizePublicApi.ps1 → build/finalize-publicapi.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# After every stable release, all PublicApi text files (Shipped & Unshipped) should be merged.
$path = "src\*\.publicApi\**\";
$directory = $PSScriptRoot;
$directory = Split-Path -Path $PSScriptRoot -Parent;

$searchPath = Join-Path -Path $directory -ChildPath $path;
Write-Host "Search Directory: $searchPath";
Expand Down Expand Up @@ -28,4 +28,4 @@ Get-ChildItem -Path $searchPath -Recurse -Filter *.Shipped.txt |
}

Write-Host "";
}
}
1 change: 1 addition & 0 deletions docs/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"resource": [
{
"files": [
".editorconfig",
"docs/**.cs",
"examples/**.cs",
"src/**.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class SqlClientInstrumentationOptions
/// <para><see cref="Activity"/>: the activity being enriched.</para>
/// <para>string: the name of the event.</para>
/// <para>object: the raw <c>SqlCommand</c> object from which additional information can be extracted to enrich the activity.</para>
/// <para>See also: <a href="https://github.com/open-telemetry/opentelemetry-dotnet/tree/master/src/OpenTelemetry.Instrumentation.SqlClient#Enrich">example</a>.</para>
/// <para>See also: <a href="https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Instrumentation.SqlClient#Enrich">example</a>.</para>
/// </remarks>
/// <example>
/// <code>
Expand Down
3 changes: 2 additions & 1 deletion src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ OpenTelemetry.Trace.TracerProviderExtensions
abstract OpenTelemetry.BaseExporter<T>.Export(in OpenTelemetry.Batch<T> batch) -> OpenTelemetry.ExportResult
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.GetAggregationType() -> OpenTelemetry.Metrics.Export.AggregationType
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.ToMetricData() -> OpenTelemetry.Metrics.Export.MetricData
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Update(T value) -> void
abstract OpenTelemetry.Metrics.BoundCounterMetricSdkBase<T>.GetAggregator() -> OpenTelemetry.Metrics.Aggregators.Aggregator<T>
abstract OpenTelemetry.Metrics.Export.MetricExporter.ExportAsync(System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<OpenTelemetry.Metrics.Export.MetricExporter.ExportResult>
abstract OpenTelemetry.Metrics.Export.MetricProcessor.FinishCollectionCycle(out System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics) -> void
Expand Down Expand Up @@ -262,3 +261,5 @@ virtual OpenTelemetry.BaseProcessor<T>.OnForceFlush(int timeoutMilliseconds) ->
virtual OpenTelemetry.BaseProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bool
virtual OpenTelemetry.BaseProcessor<T>.OnStart(T data) -> void
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Checkpoint() -> void
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.HasCheckpointData() -> bool
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Update(T value) -> void
3 changes: 2 additions & 1 deletion src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ OpenTelemetry.Trace.TracerProviderExtensions
abstract OpenTelemetry.BaseExporter<T>.Export(in OpenTelemetry.Batch<T> batch) -> OpenTelemetry.ExportResult
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.GetAggregationType() -> OpenTelemetry.Metrics.Export.AggregationType
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.ToMetricData() -> OpenTelemetry.Metrics.Export.MetricData
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Update(T value) -> void
abstract OpenTelemetry.Metrics.BoundCounterMetricSdkBase<T>.GetAggregator() -> OpenTelemetry.Metrics.Aggregators.Aggregator<T>
abstract OpenTelemetry.Metrics.Export.MetricExporter.ExportAsync(System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<OpenTelemetry.Metrics.Export.MetricExporter.ExportResult>
abstract OpenTelemetry.Metrics.Export.MetricProcessor.FinishCollectionCycle(out System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics) -> void
Expand Down Expand Up @@ -262,3 +261,5 @@ virtual OpenTelemetry.BaseProcessor<T>.OnForceFlush(int timeoutMilliseconds) ->
virtual OpenTelemetry.BaseProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bool
virtual OpenTelemetry.BaseProcessor<T>.OnStart(T data) -> void
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Checkpoint() -> void
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.HasCheckpointData() -> bool
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Update(T value) -> void
3 changes: 2 additions & 1 deletion src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ OpenTelemetry.Trace.TracerProviderExtensions
abstract OpenTelemetry.BaseExporter<T>.Export(in OpenTelemetry.Batch<T> batch) -> OpenTelemetry.ExportResult
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.GetAggregationType() -> OpenTelemetry.Metrics.Export.AggregationType
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.ToMetricData() -> OpenTelemetry.Metrics.Export.MetricData
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Update(T value) -> void
abstract OpenTelemetry.Metrics.BoundCounterMetricSdkBase<T>.GetAggregator() -> OpenTelemetry.Metrics.Aggregators.Aggregator<T>
abstract OpenTelemetry.Metrics.Export.MetricExporter.ExportAsync(System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<OpenTelemetry.Metrics.Export.MetricExporter.ExportResult>
abstract OpenTelemetry.Metrics.Export.MetricProcessor.FinishCollectionCycle(out System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics) -> void
Expand Down Expand Up @@ -287,3 +286,5 @@ virtual OpenTelemetry.BaseProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bo
virtual OpenTelemetry.BaseProcessor<T>.OnStart(T data) -> void
virtual OpenTelemetry.Logs.OpenTelemetryLoggerProvider.Dispose(bool disposing) -> void
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Checkpoint() -> void
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.HasCheckpointData() -> bool
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Update(T value) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ OpenTelemetry.Trace.TracerProviderExtensions
abstract OpenTelemetry.BaseExporter<T>.Export(in OpenTelemetry.Batch<T> batch) -> OpenTelemetry.ExportResult
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.GetAggregationType() -> OpenTelemetry.Metrics.Export.AggregationType
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.ToMetricData() -> OpenTelemetry.Metrics.Export.MetricData
abstract OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Update(T value) -> void
abstract OpenTelemetry.Metrics.BoundCounterMetricSdkBase<T>.GetAggregator() -> OpenTelemetry.Metrics.Aggregators.Aggregator<T>
abstract OpenTelemetry.Metrics.Export.MetricExporter.ExportAsync(System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<OpenTelemetry.Metrics.Export.MetricExporter.ExportResult>
abstract OpenTelemetry.Metrics.Export.MetricProcessor.FinishCollectionCycle(out System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics) -> void
Expand Down Expand Up @@ -287,3 +286,5 @@ virtual OpenTelemetry.BaseProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bo
virtual OpenTelemetry.BaseProcessor<T>.OnStart(T data) -> void
virtual OpenTelemetry.Logs.OpenTelemetryLoggerProvider.Dispose(bool disposing) -> void
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Checkpoint() -> void
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.HasCheckpointData() -> bool
virtual OpenTelemetry.Metrics.Aggregators.Aggregator<T>.Update(T value) -> void
4 changes: 4 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
them to supported data types (long for int/short, double for float). For
invalid attributes we now throw an exception instead of logging an error.
([#1720](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1720))
* Merging "this" resource with an "other" resource now prioritizes the "other"
resource's attributes in a conflict. We've rectified to follow a recent
change to the spec. We previously prioritized "this" resource's tags.
([#1728](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1728))

## 1.0.0-rc1.1

Expand Down
48 changes: 40 additions & 8 deletions src/OpenTelemetry/Metrics/Aggregators/Aggregator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,44 @@ namespace OpenTelemetry.Metrics.Aggregators
public abstract class Aggregator<T>
where T : struct
{
private long startTimeTicks;
private long checkpointStartTimeTicks;
private AggState active;
private AggState checkpoint;

protected Aggregator()
{
this.startTimeTicks = DateTimeOffset.UtcNow.Ticks;
this.checkpoint = new AggState();
this.active = new AggState();
}

/// <summary>
/// Adds value to the running total in a thread safe manner.
/// </summary>
/// <param name="value">Value to be aggregated.</param>
public abstract void Update(T value);
public virtual void Update(T value)
{
this.active.Increment();
}

/// <summary>
/// Checkpoints the current aggregate data, and resets the state.
/// </summary>
public virtual void Checkpoint()
{
// checkpoints the start time for the current aggregation, and sets the new start time.
this.checkpointStartTimeTicks = Interlocked.Exchange(ref this.startTimeTicks, DateTimeOffset.UtcNow.Ticks);
this.checkpoint = Interlocked.Exchange(ref this.active, new AggState());
}

/// <summary>
/// Check if checkpoint has any aggregated data.
/// </summary>
/// <returns>true if data was presented to aggregator.</returns>
public virtual bool HasCheckpointData()
{
return this.checkpoint.Count > 0;
}

/// <summary>
/// Convert Aggregator data to MetricData.
/// Convert checkpoint aggregator data to MetricData.
/// </summary>
/// <returns>An instance of <see cref="MetricData"/> representing the currently aggregated value.</returns>
public abstract MetricData ToMetricData();
Expand All @@ -69,7 +82,7 @@ public virtual void Checkpoint()
/// <returns>The end timestamp of the last aggregated checkpoint.</returns>
protected DateTimeOffset GetLastEndTimestamp()
{
return new DateTimeOffset(this.startTimeTicks, TimeSpan.Zero).Subtract(TimeSpan.FromTicks(1));
return new DateTimeOffset(this.active.StartTimeTicks, TimeSpan.Zero).Subtract(TimeSpan.FromTicks(1));
}

/// <summary>
Expand All @@ -78,7 +91,26 @@ protected DateTimeOffset GetLastEndTimestamp()
/// <returns>The start timestamp of the last aggregated checkpoint.</returns>
protected DateTimeOffset GetLastStartTimestamp()
{
return new DateTimeOffset(this.checkpointStartTimeTicks, TimeSpan.Zero);
return new DateTimeOffset(this.checkpoint.StartTimeTicks, TimeSpan.Zero);
}

private class AggState
{
private long count = 0;

public AggState()
{
this.StartTimeTicks = DateTimeOffset.UtcNow.Ticks;
}

public long Count { get => this.count; }

public long StartTimeTicks { get; }

public void Increment()
{
Interlocked.Increment(ref this.count);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public override AggregationType GetAggregationType()
/// <inheritdoc/>
public override void Update(double value)
{
base.Update(value);

// Adds value to the running total in a thread safe manner.
double initialTotal, computedTotal;
do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public override AggregationType GetAggregationType()
/// <inheritdoc/>
public override void Update(double newValue)
{
base.Update(newValue);
Interlocked.Exchange(ref this.value, newValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public override void Update(double value)
{
lock (this.updateLock)
{
base.Update(value);
this.summary.Count++;
this.summary.Sum += value;
this.summary.Max = Math.Max(this.summary.Max, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public override AggregationType GetAggregationType()
/// <inheritdoc/>
public override void Update(long value)
{
base.Update(value);

// Adds value to the running total in a thread safe manner.
Interlocked.Add(ref this.sum, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public override AggregationType GetAggregationType()
/// <inheritdoc/>
public override void Update(long newValue)
{
base.Update(newValue);
Interlocked.Exchange(ref this.value, newValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public override void Update(long value)
{
lock (this.updateLock)
{
base.Update(value);
this.summary.Count++;
this.summary.Sum += value;
this.summary.Max = Math.Max(this.summary.Max, value);
Expand Down
Loading

0 comments on commit 1584a6a

Please sign in to comment.