forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] [exporter/azuremonitor] Incorporate SDK Version Tagging in Az…
…ure Monitor Exporter (open-telemetry#28999) **Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> This pull request enhances the Azure Monitor Exporter by tagging telemetry data with the OpenTelemetry Collector's internal SDK version. This additional metadata will facilitate improved monitoring, troubleshooting, and analysis of data sourced from different versions of the collector. **Changes:** - Added functionality in `azuremonitorexporter` to append the SDK version to each telemetry envelope. - Implemented `getCollectorVersion` to dynamically fetch the current version of the OpenTelemetry Collector. **Sample SDK Version String:** - The SDK version string is formatted as follows: `otelc-<version>-<os>-<arch>` - Example: `otelc-v0.88.1-lin-amd64` **Note:** - Since this change pertains to internal diagnostic data enrichment and does not modify any external behavior or configuration interfaces, it does not necessitate a changelog entry. **Link to tracking Issue:** <Issue number if applicable> **Testing:** <Describe what testing was performed and which tests were added.> - Adjusted existing unit tests to ensure the SDK version string is correctly included in the telemetry envelopes. ```json { "ver": 1, "name": "Microsoft.ApplicationInsights.RemoteDependency", "time": "2023-11-06T15:21:12.9807976-08:00", "sampleRate": 100, "seq": "", "iKey": "Ikey", "tags": { "ai.cloud.role": "otlp-test", "ai.cloud.roleInstance": "2c4a6d1b-f7cb-4579-8d05-65b83b4acf7e", *"ai.internal.sdkVersion": "otelc-v0.88.1-lin-amd64",* "ai.operation.id": "0e3a010cb64d919aa8f214bf0a166334", "ai.operation.parentId": "" }, "data": { } } ``` --------- Co-authored-by: Yang Song <[email protected]>
- Loading branch information
1 parent
5f5844b
commit 4f4107d
Showing
8 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package azuremonitorexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter" | ||
|
||
import ( | ||
"runtime" | ||
"runtime/debug" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
var ( | ||
once sync.Once | ||
cachedVersion string | ||
) | ||
|
||
func getCollectorVersion() string { | ||
once.Do(func() { | ||
osInformation := runtime.GOOS[:3] + "-" + runtime.GOARCH | ||
unknownVersion := "otelc-unknown-" + osInformation | ||
|
||
info, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
cachedVersion = unknownVersion | ||
return | ||
} | ||
|
||
for _, mod := range info.Deps { | ||
if mod.Path == "go.opentelemetry.io/collector" { | ||
// Extract the semantic version without metadata. | ||
semVer := strings.SplitN(mod.Version, "-", 2)[0] | ||
cachedVersion = "otelc-" + semVer + "-" + osInformation | ||
return | ||
} | ||
} | ||
|
||
cachedVersion = unknownVersion | ||
}) | ||
|
||
return cachedVersion | ||
} |