Skip to content

Rename StackDrive to GoogleCloud and update libraries to latest version #2857

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ body:
- OpenTelemetry.Exporter.InfluxDB
- OpenTelemetry.Exporter.Instana
- OpenTelemetry.Exporter.OneCollector
- OpenTelemetry.Exporter.Stackdriver
- OpenTelemetry.Exporter.GoogleCloud
- OpenTelemetry.Extensions
- OpenTelemetry.Extensions.AWS
- OpenTelemetry.Extensions.Enrichment
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ body:
- OpenTelemetry.Exporter.InfluxDB
- OpenTelemetry.Exporter.Instana
- OpenTelemetry.Exporter.OneCollector
- OpenTelemetry.Exporter.Stackdriver
- OpenTelemetry.Exporter.GoogleCloud
- OpenTelemetry.Extensions
- OpenTelemetry.Extensions.AWS
- OpenTelemetry.Extensions.Enrichment
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/release_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ body:
- OpenTelemetry.Exporter.InfluxDB
- OpenTelemetry.Exporter.Instana
- OpenTelemetry.Exporter.OneCollector
- OpenTelemetry.Exporter.Stackdriver
- OpenTelemetry.Exporter.GoogleCloud
- OpenTelemetry.Extensions
- OpenTelemetry.Extensions.AWS
- OpenTelemetry.Extensions.Enrichment
Expand Down
4 changes: 2 additions & 2 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ flags:
paths:
- src/OpenTelemetry.Exporter.OneCollector

unittests-Exporter.Stackdriver:
unittests-Exporter.GoogleCloud:
carryforward: true
paths:
- src/OpenTelemetry.Exporter.Stackdriver
- src/OpenTelemetry.Exporter.GoogleCloud

unittests-Extensions:
carryforward: true
Expand Down
4 changes: 2 additions & 2 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ components:
- zivaninstana
src/OpenTelemetry.Exporter.OneCollector/:
- rajkumar-rangaraj
src/OpenTelemetry.Exporter.Stackdriver/:
src/OpenTelemetry.Exporter.GoogleCloudMonitoring /:
- SergeyKanzhelev
src/OpenTelemetry.Extensions/:
- mikegoldsmith
Expand Down Expand Up @@ -99,7 +99,7 @@ components:
- rajkumar-rangaraj
test/OpenTelemetry.Exporter.OneCollector.Tests/:
- rajkumar-rangaraj
test/OpenTelemetry.Exporter.Stackdriver.Tests/:
test/OpenTelemetry.Exporter.GoogleCloudMonitoring .Tests/:
- SergeyKanzhelev
test/OpenTelemetry.Extensions.Tests/:
- mikegoldsmith
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
exporter-influxdb: ['*/OpenTelemetry.Exporter.InfluxDB*/**', '!**/*.md']
exporter-instana: ['*/OpenTelemetry.Exporter.Instana*/**', '!**/*.md']
exporter-onecollector: ['*/OpenTelemetry.Exporter.OneCollector*/**', '!**/*.md']
exporter-stackdriver: ['*/OpenTelemetry.Exporter.Stackdriver*/**', '!**/*.md']
exporter-googlecloud: ['*/OpenTelemetry.Exporter.GoogleCloud*/**', '!**/*.md']
extensions: ['*/OpenTelemetry.Extensions/**', '*/OpenTelemetry.Extensions.Tests/**', '!**/*.md']
extensions-enrichment: ['*/OpenTelemetry.Extensions.Enrichment*/**', '!**/*.md']
instrumentation-aspnet: ['*/OpenTelemetry.Instrumentation.AspNet/**', '*/OpenTelemetry.Instrumentation.AspNet.Tests/**', '*/OpenTelemetry.Instrumentation.OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.*/**', 'examples/AspNet/**', '!**/*.md']
Expand Down Expand Up @@ -142,16 +142,16 @@ jobs:
project-name: Component[OpenTelemetry.Exporter.OneCollector]
code-cov-name: Exporter.OneCollector

build-test-exporter-stackdriver:
build-test-exporter-googlecloud:
needs: detect-changes
if: |
contains(needs.detect-changes.outputs.changes, 'exporter-stackdriver')
contains(needs.detect-changes.outputs.changes, 'exporter-googlecloud')
|| contains(needs.detect-changes.outputs.changes, 'build')
|| contains(needs.detect-changes.outputs.changes, 'shared')
uses: ./.github/workflows/Component.BuildTest.yml
with:
project-name: Component[OpenTelemetry.Exporter.Stackdriver]
code-cov-name: Exporter.Stackdriver
project-name: Component[OpenTelemetry.Exporter.GoogleCloud]
code-cov-name: Exporter.GoogleCloudMonitoring

build-test-extensions:
needs: detect-changes
Expand Down Expand Up @@ -606,7 +606,7 @@ jobs:
build-test-exporter-influxdb,
build-test-exporter-instana,
build-test-exporter-onecollector,
build-test-exporter-stackdriver,
build-test-exporter-googlecloud,
build-test-extensions,
build-test-extensions-enrichment,
build-test-instrumentation-aspnet,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- OpenTelemetry.Exporter.InfluxDB
- OpenTelemetry.Exporter.Instana
- OpenTelemetry.Exporter.OneCollector
- OpenTelemetry.Exporter.Stackdriver
- OpenTelemetry.Exporter.GoogleCloud
- OpenTelemetry.Extensions
- OpenTelemetry.Extensions.AWS
- OpenTelemetry.Extensions.Enrichment
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-dotnet-contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "owin", "owin", "{8D11A34C-D
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.Owin", "examples\owin\Examples.Owin.csproj", "{6B3AA3F2-89A7-433F-918A-1E5E6AAF8423}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Stackdriver", "src\OpenTelemetry.Exporter.Stackdriver\OpenTelemetry.Exporter.Stackdriver.csproj", "{8A25B43D-BBB2-40FF-B0EB-33AACCD15AD7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.GoogleCloud", "src\OpenTelemetry.Exporter.GoogleCloud\OpenTelemetry.Exporter.GoogleCloud.csproj", "{8A25B43D-BBB2-40FF-B0EB-33AACCD15AD7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Stackdriver.Tests", "test\OpenTelemetry.Exporter.Stackdriver.Tests\OpenTelemetry.Exporter.Stackdriver.Tests.csproj", "{8DABC11A-624E-4554-ACA4-D5B80146B9C6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.GoogleCloud.Tests", "test\OpenTelemetry.Exporter.GoogleCloud.Tests\OpenTelemetry.Exporter.GoogleCloud.Tests.csproj", "{8DABC11A-624E-4554-ACA4-D5B80146B9C6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.ElasticsearchClient", "src\OpenTelemetry.Instrumentation.ElasticsearchClient\OpenTelemetry.Instrumentation.ElasticsearchClient.csproj", "{96F5B85B-402B-4DFB-AF31-33D5A2EBE35B}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@

* Updated OpenTelemetry core component version(s) to `1.12.0`.
([#2725](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2725))

* Rename the namespaces to replace the `StackDrive` with GoogleCloud from them:
1. `OpenTelemetry.Exporter.Stackdriver` ->
`OpenTelemetry.Exporter.GoogleCloud`
2. `OpenTelemetry.Exporter.StackdriverImplementation` ->
`OpenTelemetry.Exporter.GoogleCloud.Implementation`
3. `OpenTelemetry.Exporter.Stackdriver.Utils` ->
`OpenTelemetry.Exporter.GoogleCloud.Utils`
* Going forward the NuGet package will be
[`OpenTelemetry.Exporter.GoogleCloud`](https://www.nuget.org/packages/OpenTelemetry.Exporter.GoogleCloud).
Older versions will remain at
[`OpenTelemetry.Exporter.Stackdriver`](https://www.nuget.org/packages/OpenTelemetry.Exporter.Stackdriver).
## 1.0.0-beta.6

Released 2024-Apr-22
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Google.Api;
using Google.Api.Gax.Grpc;
using Google.Api.Gax.ResourceNames;
using Google.Cloud.Monitoring.V3;
using Google.Protobuf.Collections;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using OpenTelemetry.Exporter.GoogleCloud.Implementation;
using OpenTelemetry.Metrics;
using Metric = OpenTelemetry.Metrics.Metric;

namespace OpenTelemetry.Exporter.GoogleCloud;

/// <summary>
/// Exports a metrics to Google Cloud Monitoring .
/// </summary>
[Obsolete("This exporter is deprecated and might be removed in a future version. Please consider using directly OTPL directly: https://cloud.google.com/stackdriver/docs/reference/telemetry/overview")]
public class GoogleCloudMonitoringExporter : BaseExporter<Metric>
{
private readonly ProjectName projectName;
private readonly MetricServiceSettings? metricServiceSettings;
private MetricServiceClient? metricServiceClient;

#pragma warning disable CA1810 // Initialize reference type static fields inline
static GoogleCloudMonitoringExporter()
#pragma warning restore CA1810 // Initialize reference type static fields inline
{
try
{
var assemblyPackageVersion = typeof(GoogleCloudTraceExporter).GetTypeInfo().Assembly
.GetCustomAttributes<AssemblyInformationalVersionAttribute>().First().InformationalVersion;
GoogleCloudMetricExportVersion = assemblyPackageVersion;
}
catch (Exception)
{
GoogleCloudMetricExportVersion = $"{Constants.PackagVersionUndefined}";
}

try
{
OpenTelemetryExporterVersion = Assembly.GetCallingAssembly().GetName().Version!.ToString();
}
catch (Exception)
{
OpenTelemetryExporterVersion = $"{Constants.PackagVersionUndefined}";
}
}

private static string OpenTelemetryExporterVersion { get; set; }

private static string GoogleCloudMetricExportVersion { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="GoogleCloudMonitoringExporter"/> class.
/// </summary>
/// <param name="projectId">Project ID to send telemetry to.</param>
public GoogleCloudMonitoringExporter(string projectId)
{
this.projectName = new ProjectName(projectId);

// Set header mutation for every outgoing API call to Google Cloud Monitoring so the BE knows
// which version of OC client is calling it as well as which version of the exporter
var callSettings = CallSettings.FromHeaderMutation(StackdriverCallHeaderAppender);
this.metricServiceSettings = new MetricServiceSettings { CallSettings = callSettings };
}

/// <summary>
/// Initializes a new instance of the <see cref="GoogleCloudMonitoringExporter"/> class.
/// Only used internally for tests.
/// </summary>
/// <param name="projectId">Project ID to send telemetry to.</param>
/// <param name="metricServiceClient">MetricServiceClient instance to use.</param>
[ExcludeFromCodeCoverage]
internal GoogleCloudMonitoringExporter(string projectId, MetricServiceClient metricServiceClient)
: this(projectId)
{
this.metricServiceClient = metricServiceClient;
}

/// <inheritdoc/>
public override ExportResult Export(in Batch<Metric> batch)
{
this.metricServiceClient ??=
new MetricServiceClientBuilder { Settings = this.metricServiceSettings, }.Build();
var timeSeriesList = new List<TimeSeries>();

foreach (var metric in batch)
{
foreach (var point in metric.GetMetricPoints())
{
var ts = CreateTimeSeriesForMetricPoint(metric, point);
timeSeriesList.Add(ts);
}
}

if (timeSeriesList.Count > 0)
{
this.metricServiceClient.CreateTimeSeries(this.projectName, timeSeriesList);
}

return ExportResult.Success;
}

private static TimeSeries CreateTimeSeriesForMetricPoint(Metric metric, MetricPoint point)
{
MetricDescriptor.Types.MetricKind metricKind;
MetricDescriptor.Types.ValueType valueType;
TypedValue value;

switch (metric.MetricType)
{
case MetricType.DoubleGauge:
metricKind = MetricDescriptor.Types.MetricKind.Gauge;
valueType = MetricDescriptor.Types.ValueType.Double;
value = new TypedValue { DoubleValue = point.GetGaugeLastValueDouble() };
break;
case MetricType.LongGauge:
metricKind = MetricDescriptor.Types.MetricKind.Gauge;
valueType = MetricDescriptor.Types.ValueType.Int64;
value = new TypedValue { Int64Value = point.GetGaugeLastValueLong() };
break;
case MetricType.DoubleSum:
metricKind = MetricDescriptor.Types.MetricKind.Cumulative;
valueType = MetricDescriptor.Types.ValueType.Double;
value = new TypedValue { DoubleValue = point.GetSumDouble() };
break;
case MetricType.LongSum:
metricKind = MetricDescriptor.Types.MetricKind.Cumulative;
valueType = MetricDescriptor.Types.ValueType.Int64;
value = new TypedValue { Int64Value = point.GetSumLong() };
break;
case MetricType.DoubleSumNonMonotonic:
metricKind = MetricDescriptor.Types.MetricKind.Gauge;
valueType = MetricDescriptor.Types.ValueType.Double;
value = new TypedValue { DoubleValue = point.GetSumDouble() };
break;
case MetricType.LongSumNonMonotonic:
metricKind = MetricDescriptor.Types.MetricKind.Gauge;
valueType = MetricDescriptor.Types.ValueType.Int64;
value = new TypedValue { Int64Value = point.GetSumLong() };
break;
case MetricType.Histogram:
metricKind = MetricDescriptor.Types.MetricKind.Cumulative;
valueType = MetricDescriptor.Types.ValueType.Distribution;
var count = point.GetHistogramCount();
var sum = point.GetHistogramSum();
var mean = count > 0 ? sum / count : 0;
var buckets = point.GetHistogramBuckets();

value = new TypedValue
{
DistributionValue = new Distribution
{
Count = count,
Mean = mean,
BucketCounts = { ToRepeatedField(buckets) },
BucketOptions = new Distribution.Types.BucketOptions
{
ExplicitBuckets = new Distribution.Types.BucketOptions.Types.Explicit
{
Bounds = { ToRepeatedFieldBounds(buckets) },
},
},
},
};
break;
case MetricType.ExponentialHistogram:
throw new NotImplementedException("ExponentialHistogram is not supported yet.");
default:
metricKind = MetricDescriptor.Types.MetricKind.Gauge;
valueType = MetricDescriptor.Types.ValueType.Double;
value = new TypedValue { DoubleValue = point.GetSumDouble() };
break;
}

return new TimeSeries
{
Metric = new Google.Api.Metric { Type = $"custom.googleapis.com/opentelemetry/{metric.Name}" },
Resource = new MonitoredResource { Type = "global" },
MetricKind = metricKind,
ValueType = valueType,
Points =
{
new Point
{
Interval = new TimeInterval
{
StartTime = Timestamp.FromDateTimeOffset(point.StartTime),
EndTime = Timestamp.FromDateTimeOffset(point.EndTime),
},
Value = value,
},
},
};
}

private static RepeatedField<long> ToRepeatedField(HistogramBuckets? buckets)
{
var result = new RepeatedField<long>();
if (buckets == null)
{
return result;
}

foreach (var count in buckets)
{
result.Add(count.BucketCount);
}

return result;
}

private static RepeatedField<double> ToRepeatedFieldBounds(HistogramBuckets? buckets)
{
var result = new RepeatedField<double>();
if (buckets == null)
{
return result;
}

foreach (var bucket in buckets)
{
result.Add(bucket.ExplicitBound);
}

return result;
}

/// <summary>
/// Appends OpenTelemetry headers for every outgoing request to Stackdriver Backend.
/// </summary>
/// <param name="metadata">The metadata that is sent with every outgoing http request.</param>
private static void StackdriverCallHeaderAppender(Metadata metadata)
{
metadata.Add("AGENT_LABEL_KEY", "g.co/agent");
metadata.Add(
"AGENT_LABEL_VALUE_STRING",
$"{OpenTelemetryExporterVersion}; googlecloud-exporter {GoogleCloudMetricExportVersion}");
}
}
Loading