1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-12-01 23:12:29 +02:00

add resource option to Provider. (#545)

- update otlp exporter to export resources.
This commit is contained in:
Rahul Patel
2020-03-13 13:07:36 -07:00
committed by GitHub
parent 638b865c90
commit 6ada85adba
11 changed files with 317 additions and 154 deletions

View File

@@ -34,6 +34,7 @@ import (
apitrace "go.opentelemetry.io/otel/api/trace"
ottest "go.opentelemetry.io/otel/internal/testing"
export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/resource"
)
var (
@@ -598,7 +599,10 @@ func TestSetSpanStatus(t *testing.T) {
}
func cmpDiff(x, y interface{}) string {
return cmp.Diff(x, y, cmp.AllowUnexported(core.Value{}), cmp.AllowUnexported(export.Event{}))
return cmp.Diff(x, y,
cmp.AllowUnexported(core.Value{}),
cmp.AllowUnexported(export.Event{}),
cmp.AllowUnexported(resource.Resource{}))
}
func remoteSpanContext() core.SpanContext {
@@ -1058,3 +1062,34 @@ func TestWithSpanKind(t *testing.T) {
}
}
}
func TestWithResource(t *testing.T) {
var te testExporter
tp, _ := NewProvider(WithSyncer(&te),
WithConfig(Config{DefaultSampler: AlwaysSample()}),
WithResourceAttributes(key.String("rk1", "rv1"), key.Int64("rk2", 5)))
span := startSpan(tp, "WithResource")
span.SetAttributes(core.Key("key1").String("value1"))
got, err := endSpan(&te, span)
if err != nil {
t.Error(err.Error())
}
want := &export.SpanData{
SpanContext: core.SpanContext{
TraceID: tid,
TraceFlags: 0x1,
},
ParentSpanID: sid,
Name: "span0",
Attributes: []core.KeyValue{
key.String("key1", "value1"),
},
SpanKind: apitrace.SpanKindInternal,
HasRemoteParent: true,
Resource: resource.New(key.String("rk1", "rv1"), key.Int64("rk2", 5)),
}
if diff := cmpDiff(got, want); diff != "" {
t.Errorf("WithResource:\n -got +want %s", diff)
}
}