Skip to content

Commit

Permalink
Merge branch 'main' into yunl/OtlpLoggingExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Ting authored Dec 23, 2023
2 parents df362e4 + e3759a1 commit a332701
Show file tree
Hide file tree
Showing 30 changed files with 801 additions and 246 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-concurrency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Publish Artifacts
if: always() && !cancelled()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.project }}-${{ matrix.version }}-coyoteoutput
path: '**/*_CoyoteOutput.*'
2 changes: 1 addition & 1 deletion .github/workflows/publish-packages-1.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: dotnet pack OpenTelemetry.proj --configuration Release --no-build --no-restore

- name: Publish Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ github.ref_name }}-packages
path: '**/bin/**/*.*nupkg'
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.github\workflows\ci-concurrency.yml = .github\workflows\ci-concurrency.yml
CONTRIBUTING.md = CONTRIBUTING.md
global.json = global.json
LICENSE = LICENSE
NuGet.config = NuGet.config
LICENSE.TXT = LICENSE.TXT
OpenTelemetry.proj = OpenTelemetry.proj
README.md = README.md
VERSIONING.md = VERSIONING.md
THIRD-PARTY-NOTICES.TXT = THIRD-PARTY-NOTICES.TXT
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7CB2F02E-03FA-4FFF-89A5-C51F107623FD}"
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ Here are the [instrumentation
libraries](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#instrumentation-library):

* [ASP.NET Core](./src/OpenTelemetry.Instrumentation.AspNetCore/README.md)
* [Grpc.Net.Client](./src/OpenTelemetry.Instrumentation.GrpcNetClient/README.md)
* [HTTP clients](./src/OpenTelemetry.Instrumentation.Http/README.md)
* [SQL client](./src/OpenTelemetry.Instrumentation.SqlClient/README.md)
* gRPC client:
[Grpc.Net.Client](./src/OpenTelemetry.Instrumentation.GrpcNetClient/README.md)
* HTTP clients: [System.Net.Http.HttpClient and
System.Net.HttpWebRequest](./src/OpenTelemetry.Instrumentation.Http/README.md)
* SQL clients: [Microsoft.Data.SqlClient and
System.Data.SqlClient](./src/OpenTelemetry.Instrumentation.SqlClient/README.md)

Here are the [exporter
libraries](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#exporter-library):
Expand Down
31 changes: 31 additions & 0 deletions THIRD-PARTY-NOTICES.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
OpenTelemetry .NET uses third-party libraries or other resources that may be
distributed under licenses different than the OpenTelemetry .NET software.

The attached notices are provided for information only.

License notice for .NET
-------------------------------

The MIT License (MIT)

Copyright (c) .NET Foundation and Contributors

All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 4 additions & 2 deletions build/Common.prod.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
<PackageTags>Observability;OpenTelemetry;Monitoring;Telemetry;Tracing;Metrics;Logging</PackageTags>
<PackageIcon>opentelemetry-icon-color.png</PackageIcon>
<PackageProjectUrl>https://opentelemetry.io</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Authors>OpenTelemetry Authors</Authors>
<Copyright>Copyright The OpenTelemetry Authors</Copyright>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageOutputPath Condition="$(Build_ArtifactStagingDirectory) != ''">$(Build_ArtifactStagingDirectory)</PackageOutputPath>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackagePrimaryLicenseFile>$(RepoRoot)\LICENSE.TXT</PackagePrimaryLicenseFile>
<PackageThirdPartyNoticesFile>$(RepoRoot)\THIRD-PARTY-NOTICES.TXT</PackageThirdPartyNoticesFile>
</PropertyGroup>

<PropertyGroup Label="SourceLinkProperties">
Expand Down
49 changes: 29 additions & 20 deletions docs/metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

## Best Practices

- Instruments SHOULD only be created once and reused throughout the application
lifetime. This
[example](../../docs/metrics/getting-started-console/Program.cs) shows how an
instrument is created a `static` field and then used in the application. You
could also look at this ASP.NET Core
[example](../../examples/AspNetCore/Program.cs) which shows a more Dependency
Injection friendly way of doing this by extracting the `Meter` and an
instrument into a dedicated class called
[Instrumentation](../../examples/AspNetCore/Instrumentation.cs) which is then
added as a `Singleton` service.

- When emitting metrics with tags, DO NOT change the order in which you provide
tags. Changing the order of tag keys would increase the time taken by the SDK
to record the measurement.
### Instruments should be singleton

Instruments SHOULD only be created once and reused throughout the application
lifetime. This [example](../../docs/metrics/getting-started-console/Program.cs)
shows how an instrument is created as a `static` field and then used in the
application. You could also look at this ASP.NET Core
[example](../../examples/AspNetCore/Program.cs) which shows a more Dependency
Injection friendly way of doing this by extracting the `Meter` and an instrument
into a dedicated class called
[Instrumentation](../../examples/AspNetCore/Instrumentation.cs) which is then
added as a `Singleton` service.

### Ordering of Tags

When emitting metrics with tags, DO NOT change the order in which you provide
tags. Changing the order of tag keys would increase the time taken by the SDK to
record the measurement.

```csharp
// If you emit the tag keys in this order: name -> color -> taste, stick to this order of tag keys for subsequent measurements.
Expand All @@ -27,6 +30,8 @@ MyFruitCounter.Add(5, new("name", "apple"), new("color", "red"), new("taste", "s
MyFruitCounter.Add(7, new("color", "red"), new("name", "apple"), new("taste", "sweet")); // <--- DON'T DO THIS
```

### Use TagList where appropriate

For the best performance, it is highly recommended to pass in tags in certain
ways so allocations are only happening on the stack rather than the heap,
which eliminates pressure on the GC (garbage collector):
Expand All @@ -49,7 +54,6 @@ var tags = new TagList
// Uses a TagList as there are more than three tags
counter.Add(100, tags); // <--- DO THIS

// Avoid the below mentioned approaches when there are more than three tags
var tag1 = new KeyValuePair<string, object>("DimName1", "DimValue1");
var tag2 = new KeyValuePair<string, object>("DimName2", "DimValue2");
Expand All @@ -63,11 +67,16 @@ counter.Add(100, readOnlySpanOfTags); // <--- DON'T DO THIS
```

- When emitting metrics with more than eight tags, the SDK allocates memory on
the hot-path. You SHOULD try to keep the number of tags less than or equal to
eight. Check if you can extract any shared tags such as `MachineName`,
`Environment` etc. into `Resource` attributes. Refer to this
[doc](../../docs/metrics/customizing-the-sdk/README.md#resource) for more
information.
the hot-path. You SHOULD try to keep the number of tags less than or equal to
eight. If you are exceeding this, check if you can model some of the tags as
Resource, as [shown here](#modeling-static-tags-as-resource).

### Modeling static tags as Resource

Tags such as `MachineName`, `Environment` etc. which are static throughout the
process lifetime should be be modeled as `Resource`, instead of adding them to
each metric measurement. Refer to this
[doc](./customizing-the-sdk/README.md#resource) for details and examples.

## Common issues that lead to missing metrics

Expand Down
7 changes: 6 additions & 1 deletion docs/metrics/customizing-the-sdk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ public class Program
public static void Main()
{
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.ConfigureResource(res => res.AddService("example-service"))
.ConfigureResource(resource => resource.AddAttributes(new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("static-attribute1", "v1"),
new KeyValuePair<string, object>("static-attribute2", "v2"),
}))
.ConfigureResource(resource => resource.AddService("MyServiceName"))
.AddMeter(Meter1.Name)
.AddMeter(Meter2.Name)

Expand Down
34 changes: 26 additions & 8 deletions docs/metrics/customizing-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,27 @@ is to use a resource indicating this
[Service](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md#service)
and [Telemetry
SDK](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md#telemetry-sdk).
The `ConfigureResource` method on `MeterProviderBuilder` can be used to set a
configure the resource on the provider. When the provider is built, it
automatically builds the final `Resource` from the configured `ResourceBuilder`.
There can only be a single `Resource` associated with a
provider. It is not possible to change the resource builder *after* the provider
is built, by calling the `Build()` method on the `MeterProviderBuilder`.
The `ConfigureResource` method on `MeterProviderBuilder` can be used to
configure the resource on the provider. `ConfigureResource` accepts an `Action`
to configure the `ResourceBuilder`. Multiple calls to `ConfigureResource` can be
made. When the provider is built, it builds the final `Resource` combining all
the `ConfigureResource` calls. There can only be a single `Resource` associated
with a provider. It is not possible to change the resource builder *after* the
provider is built, by calling the `Build()` method on the
`MeterProviderBuilder`.

`ResourceBuilder` offers various methods to construct resource comprising of
multiple attributes from various sources.
attributes from various sources. For example, `AddService()` adds
[Service](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md#service)
resource. `AddAttributes` can be used to add any additional attributes to the
`Resource`. It also allows adding `ResourceDetector`s.

It is recommended to model attributes that are static throughout the lifetime of
the process as Resources, instead of adding them as attributes(tags) on each
measurement.

Follow [this](../../trace/extending-the-sdk/README.md#resource-detector) document
to learn about writing custom resource detectors.

The snippet below shows configuring the `Resource` associated with the provider.

Expand All @@ -594,7 +607,12 @@ using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;

using var meterProvider = Sdk.CreateMeterProviderBuilder()
.ConfigureResource(r => r.AddService("MyServiceName"))
.ConfigureResource(r => r.AddAttributes(new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("static-attribute1", "v1"),
new KeyValuePair<string, object>("static-attribute2", "v2"),
}))
.ConfigureResource(resourceBuilder => resourceBuilder.AddService("service-name"))
.Build();
```

Expand Down
10 changes: 9 additions & 1 deletion docs/trace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Best Practices

### ActivitySource singleton
### ActivitySource should be singleton

`ActivitySource` SHOULD only be created once and reused throughout the
application lifetime. This
Expand Down Expand Up @@ -31,6 +31,14 @@ care of propagating/restoring the context across process boundaries. If the
you need, it is generally recommended to enrich the existing Activity with that
information, as opposed to creating a new one.

### Modelling static tags as Resource

Tags such as `MachineName`, `Environment` etc. which are static throughout the
process lifetime should be be modelled as `Resource`, instead of adding them
to each `Activity`. Refer to this
[doc](./customizing-the-sdk/README.md#resource) for details and
examples.

## Common issues that lead to missing traces

- The `ActivitySource` used to create the `Activity` is not added to the
Expand Down
8 changes: 6 additions & 2 deletions docs/trace/customizing-the-sdk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ public static void Main()
// The following adds subscription to activities from all Activity Sources
// whose name starts with "AbcCompany.XyzProduct.".
.AddSource("AbcCompany.XyzProduct.*")
.ConfigureResource(resourceBuilder => resourceBuilder.AddTelemetrySdk())
.ConfigureResource(r => r.AddService("MyServiceName"))
.ConfigureResource(resource => resource.AddAttributes(new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("static-attribute1", "v1"),
new KeyValuePair<string, object>("static-attribute2", "v2"),
}))
.ConfigureResource(resource => resource.AddService("MyServiceName"))
.AddConsoleExporter()
.Build();

Expand Down
18 changes: 12 additions & 6 deletions docs/trace/customizing-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,14 @@ provider is built, by calling the `Build()` method on the
`TracerProviderBuilder`.

`ResourceBuilder` offers various methods to construct resource comprising of
multiple attributes from various sources. Examples include `AddTelemetrySdk()`
which adds [Telemetry
Sdk](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md#telemetry-sdk)
resource, and `AddService()` which adds
attributes from various sources. For example, `AddService()` adds
[Service](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md#service)
resource. It also allows adding `ResourceDetector`s.
resource. `AddAttributes` can be used to add any additional attribute to the
`Resource`. It also allows adding `ResourceDetector`s.

It is recommended to model attributes that are static throughout the lifetime of
the process as Resources, instead of adding them as attributes(tags) on each
`Activity`.

Follow [this](../extending-the-sdk/README.md#resource-detector) document
to learn about writing custom resource detectors.
Expand All @@ -321,7 +323,11 @@ using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

var tracerProvider = Sdk.CreateTracerProviderBuilder()
.ConfigureResource(resourceBuilder => resourceBuilder.AddTelemetrySdk())
.ConfigureResource(r => r.AddAttributes(new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("static-attribute1", "v1"),
new KeyValuePair<string, object>("static-attribute2", "v2"),
}))
.ConfigureResource(resourceBuilder => resourceBuilder.AddService("service-name"))
.Build();
```
Expand Down
2 changes: 1 addition & 1 deletion examples/AspNetCore/Instrumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Instrumentation()
string? version = typeof(Instrumentation).Assembly.GetName().Version?.ToString();
this.ActivitySource = new ActivitySource(ActivitySourceName, version);
this.meter = new Meter(MeterName, version);
this.FreezingDaysCounter = this.meter.CreateCounter<long>("weather.days.freezing", "The number of days where the temperature is below freezing");
this.FreezingDaysCounter = this.meter.CreateCounter<long>("weather.days.freezing", description: "The number of days where the temperature is below freezing");
}

public ActivitySource ActivitySource { get; }
Expand Down
11 changes: 11 additions & 0 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@
<Using Remove="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition="'$(IsPackable)' == 'true'">
<None Include="$(PackagePrimaryLicenseFile)"
PackagePath="$([System.IO.Path]::GetFileName('$(PackagePrimaryLicenseFile)'))"
Pack="true"
Visible="false" />
<None Include="$(PackageThirdPartyNoticesFile)"
PackagePath="$([System.IO.Path]::GetFileName('$(PackageThirdPartyNoticesFile)'))"
Pack="true"
Visible="false" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## Unreleased

* Export OpenMetrics format from Prometheus exporters ([#5107](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5107))
* For requests with OpenMetrics format, scope info is automatically added
([#5086](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5086)
[#5182](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5182))

## 1.7.0-rc.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## Unreleased

* Export OpenMetrics format from Prometheus exporters ([#5107](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5107))
* For requests with OpenMetrics format, scope info is automatically added
([#5086](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5086)
[#5182](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5182))

## 1.7.0-rc.1

Expand Down
Loading

0 comments on commit a332701

Please sign in to comment.