-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[service] Move TracerProvider initialization to service/telemetry pac…
…kage
- Loading branch information
Showing
10 changed files
with
302 additions
and
265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package resource // import "go.opentelemetry.io/collector/service/internal/resource" | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/sdk/resource" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
semconv "go.opentelemetry.io/collector/semconv/v1.18.0" | ||
) | ||
|
||
// New resource from telemetry configuration. | ||
func New(buildInfo component.BuildInfo, resourceCfg map[string]*string) *resource.Resource { | ||
var telAttrs []attribute.KeyValue | ||
|
||
for k, v := range resourceCfg { | ||
// nil value indicates that the attribute should not be included in the telemetry. | ||
if v != nil { | ||
telAttrs = append(telAttrs, attribute.String(k, *v)) | ||
} | ||
} | ||
|
||
if _, ok := resourceCfg[semconv.AttributeServiceName]; !ok { | ||
// AttributeServiceName is not specified in the config. Use the default service name. | ||
telAttrs = append(telAttrs, attribute.String(semconv.AttributeServiceName, buildInfo.Command)) | ||
} | ||
|
||
if _, ok := resourceCfg[semconv.AttributeServiceInstanceID]; !ok { | ||
// AttributeServiceInstanceID is not specified in the config. Auto-generate one. | ||
instanceUUID, _ := uuid.NewRandom() | ||
instanceID := instanceUUID.String() | ||
telAttrs = append(telAttrs, attribute.String(semconv.AttributeServiceInstanceID, instanceID)) | ||
} | ||
|
||
if _, ok := resourceCfg[semconv.AttributeServiceVersion]; !ok { | ||
// AttributeServiceVersion is not specified in the config. Use the actual | ||
// build version. | ||
telAttrs = append(telAttrs, attribute.String(semconv.AttributeServiceVersion, buildInfo.Version)) | ||
} | ||
return resource.NewWithAttributes(semconv.SchemaURL, telAttrs...) | ||
} |
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
Oops, something went wrong.