-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathOpenTelemetryPlatformService.cs
More file actions
35 lines (25 loc) · 1.77 KB
/
OpenTelemetryPlatformService.cs
File metadata and controls
35 lines (25 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Diagnostics.Metrics;
using Microsoft.Testing.Platform.Telemetry;
namespace Microsoft.Testing.Extensions.OpenTelemetry;
internal sealed class OpenTelemetryPlatformService : IPlatformOpenTelemetryService
{
internal const string ActivitySourceName = "Microsoft.Testing.Platform";
internal const string MeterName = "Microsoft.Testing.Platform";
private readonly ActivitySource _activitySource = new(ActivitySourceName, PlatformVersion.Version);
private readonly Meter _meter = new(MeterName, PlatformVersion.Version);
public IPlatformActivity? TestFrameworkActivity { get; set; }
public IPlatformActivity? StartActivity([CallerMemberName] string name = "", IEnumerable<KeyValuePair<string, object?>>? tags = null, string? parentId = null, DateTimeOffset startTime = default)
=> _activitySource.StartActivity(name, ActivityKind.Internal, tags: tags, startTime: startTime, parentId: parentId) is Activity activity
? new ActivityWrapper(activity)
: null;
public ICounter<T> CreateCounter<T>(string name, string? unit = null, string? description = null, IEnumerable<KeyValuePair<string, object?>>? tags = null)
where T : struct
=> new CounterWrapper<T>(_meter.CreateCounter<T>(name, unit, description, tags));
public IHistogram<T> CreateHistogram<T>(string name, string? unit = null, string? description = null, IEnumerable<KeyValuePair<string, object?>>? tags = null)
where T : struct
=> new HistogramWrapper<T>(_meter.CreateHistogram<T>(name, unit, description, tags));
public void Dispose()
=> _activitySource.Dispose();
}