-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] custom user-agent (& expanding OTEL_EXPORTER_OTLP_* env var su…
…pport) (#94) * customize the user-agent of the OLTP exporter Instead of the Go autoinst agent appearing to telemetry data receivers as only the version of grpc-go against which it was built, this adds an identifier to the User-Agent header via the dial options parameter support within otlptracegrpc. To help troubleshooting data transmission, runtime operating system and CPU architecture is included in the user-agent within a parenthetical comment in accordance with the header's specification.[1] This replaces the low-level build up of a gRPC client connection with a reuse of the OTel Go SDK's grpc trace client constructor. A happy byproduct of using the SDK's constructor is that all of the OTEL_EXPORTER_OTLP_* environment variables related to exporting traces ought to be supported now, obviating the need to maintain code here to retrieve, interpret, and handle them. [1] RFC 7231 https://www.rfc-editor.org/rfc/rfc7231#section-5.5.3 though more readable documentation about this header spec is available at MDN Web Docs: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent * add release version to user-agent and Auto attribute * an attempt at adding unit tests This is an expendable commit if folks don't like it. * tack tests onto end of generate instead? * include scheme for endpoint Spec and therefore SDK require the URL scheme in ENDPOINT values. * update e2e expectations This Go auto-inst adds its version to resource attributes now. * new version.go for the auto package The version declared here will get bumped when using the multimod releaser utility. The agent's controller uses this version to include in the User-Agent header and in a resource attribute for outgoing telemetry. * test potentially testable modules Modeled after the test targets in OpenTelemetry Go. Removes the "maybe use gotestsum if you've got it!" option. * improve code comment for auto.Version() Co-authored-by: Tyler Yahn <[email protected]> * test is PHONY Always Be Testing. Co-authored-by: Tyler Yahn <[email protected]> --------- Co-authored-by: Tyler Yahn <[email protected]>
- Loading branch information
Showing
12 changed files
with
163 additions
and
25 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,27 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opentelemetry | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/auto" | ||
) | ||
|
||
func TestUserAgent(t *testing.T) { | ||
assert.Contains(t, autoinstUserAgent, fmt.Sprintf("OTel-Go-Auto-Instrumentation/%s", auto.Version())) | ||
} |
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,20 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package auto | ||
|
||
// Version is the current release version of OpenTelemetry Go auto-instrumentation in use. | ||
func Version() string { | ||
return "v0.1.0-alpha" | ||
} |
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,54 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package auto | ||
|
||
import ( | ||
"io/ioutil" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
// regex taken from https://github.com/Masterminds/semver/tree/v3.1.1 | ||
var versionRegex = regexp.MustCompile(`^v?([0-9]+)(\.[0-9]+)?(\.[0-9]+)?` + | ||
`(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?` + | ||
`(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$`) | ||
|
||
func TestVersionSemver(t *testing.T) { | ||
v := Version() | ||
assert.NotNil(t, versionRegex.FindStringSubmatch(v), "version is not semver: %s", v) | ||
} | ||
|
||
func TestVersionMatchesYaml(t *testing.T) { | ||
versionYaml, err := ioutil.ReadFile("versions.yaml") | ||
if err != nil { | ||
t.Fatalf("Couldn't read versions.yaml file: %e", err) | ||
return | ||
} | ||
|
||
var versionInfo map[string]interface{} | ||
|
||
err = yaml.Unmarshal(versionYaml, &versionInfo) | ||
if err != nil { | ||
t.Fatalf("Couldn't parse version.yaml: %e", err) | ||
return | ||
} | ||
|
||
// incredibad, but it's where the intended version is declared at the moment | ||
expectedVersion := versionInfo["module-sets"].(map[string]interface{})["alpha"].(map[string]interface{})["version"] | ||
assert.Equal(t, expectedVersion, Version(), "Build version should match versions.yaml.") | ||
} |