Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Update to OpenTelemetry 0.18.0 #71

Merged
merged 3 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions examples/simple/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/newrelic/opentelemetry-exporter-go/examples/simple
go 1.15

require (
github.com/newrelic/newrelic-telemetry-sdk-go v0.5.1
github.com/newrelic/opentelemetry-exporter-go v0.15.1
go.opentelemetry.io/otel v0.16.0
go.opentelemetry.io/otel/sdk v0.16.0
github.com/newrelic/newrelic-telemetry-sdk-go v0.5.2
github.com/newrelic/opentelemetry-exporter-go v0.17.0
go.opentelemetry.io/otel v0.18.0
go.opentelemetry.io/otel/sdk v0.18.0
)
14 changes: 7 additions & 7 deletions examples/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/newrelic/newrelic-telemetry-sdk-go/telemetry"
"github.com/newrelic/opentelemetry-exporter-go/newrelic"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/propagation"
Expand Down Expand Up @@ -82,12 +82,12 @@ func main() {
otel.SetTextMapPropagator(propagator)

// Sample metric instruments
fooKey := label.Key("ex.com/foo")
barKey := label.Key("ex.com/bar")
lemonsKey := label.Key("ex.com/lemons")
anotherKey := label.Key("ex.com/another")
fooKey := attribute.Key("ex.com/foo")
barKey := attribute.Key("ex.com/bar")
lemonsKey := attribute.Key("ex.com/lemons")
anotherKey := attribute.Key("ex.com/another")

commonLabels := []label.KeyValue{lemonsKey.Int(10), label.String("A", "1"), label.String("B", "2"), label.String("C", "3")}
commonLabels := []attribute.KeyValue{lemonsKey.Int(10), attribute.String("A", "1"), attribute.String("B", "2"), attribute.String("C", "3")}

meter := global.Meter("ex.com/basic")

Expand Down Expand Up @@ -116,7 +116,7 @@ func main() {
trace.WithSpanKind(trace.SpanKindServer))
defer span.End()

span.AddEvent("Nice operation!", trace.WithAttributes(label.Int("bogons", 100)))
span.AddEvent("Nice operation!", trace.WithAttributes(attribute.Int("bogons", 100)))
span.SetAttributes(anotherKey.String("yes"))

meter.RecordBatch(
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ go 1.14

require (
github.com/newrelic/newrelic-telemetry-sdk-go v0.5.2
go.opentelemetry.io/otel v0.17.0
go.opentelemetry.io/otel/metric v0.17.0
go.opentelemetry.io/otel/sdk v0.17.0
go.opentelemetry.io/otel/sdk/export/metric v0.17.0
go.opentelemetry.io/otel/sdk/metric v0.17.0
go.opentelemetry.io/otel/trace v0.17.0
go.opentelemetry.io/otel v0.18.0
go.opentelemetry.io/otel/metric v0.18.0
go.opentelemetry.io/otel/sdk v0.18.0
go.opentelemetry.io/otel/sdk/export/metric v0.18.0
go.opentelemetry.io/otel/sdk/metric v0.18.0
go.opentelemetry.io/otel/trace v0.18.0
)
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
go.opentelemetry.io/otel v0.17.0 h1:6MKOu8WY4hmfpQ4oQn34u6rYhnf2sWf1LXYO/UFm71U=
go.opentelemetry.io/otel v0.17.0/go.mod h1:Oqtdxmf7UtEvL037ohlgnaYa1h7GtMh0NcSd9eqkC9s=
go.opentelemetry.io/otel/metric v0.17.0 h1:t+5EioN8YFXQ2EH+1j6FHCKMUj+57zIDSnSGr/mWuug=
go.opentelemetry.io/otel/metric v0.17.0/go.mod h1:hUz9lH1rNXyEwWAhIWCMFWKhYtpASgSnObJFnU26dJ0=
go.opentelemetry.io/otel/oteltest v0.17.0 h1:TyAihUowTDLqb4+m5ePAsR71xPJaTBJl4KDArIdi9k4=
go.opentelemetry.io/otel/oteltest v0.17.0/go.mod h1:JT/LGFxPwpN+nlsTiinSYjdIx3hZIGqHCpChcIZmdoE=
go.opentelemetry.io/otel/sdk v0.17.0 h1:eHXQwanmbtSHM/GcJYbJ8FyyH/sT9a0e+1Z9ZWkF7Ug=
go.opentelemetry.io/otel/sdk v0.17.0/go.mod h1:INs1PePjjF2hf842AXsxGTe5lH023QfLTZRFPiV/RUk=
go.opentelemetry.io/otel/sdk/export/metric v0.17.0 h1:RKOa26LDq4JBRwUnWwY64ccc27v1rA20z0q71aq4WFs=
go.opentelemetry.io/otel/sdk/export/metric v0.17.0/go.mod h1:G9SxRFvGmGpdmJ8TEXnTEnnRuR5p3cg/tRvWkA/XHvo=
go.opentelemetry.io/otel/sdk/metric v0.17.0 h1:l9W/OcHwyq3ZPqk4V6OS5ED50z9A6yI8N9gWeKS7zAY=
go.opentelemetry.io/otel/sdk/metric v0.17.0/go.mod h1:zAX55SrmDMpZwfQrz1PKIPbCP5beU+JPQTfNko01deo=
go.opentelemetry.io/otel/trace v0.17.0 h1:SBOj64/GAOyWzs5F680yW1ITIfJkm6cJWL2YAvuL9xY=
go.opentelemetry.io/otel/trace v0.17.0/go.mod h1:bIujpqg6ZL6xUTubIUgziI1jSaUPthmabA/ygf/6Cfg=
go.opentelemetry.io/otel v0.18.0 h1:d5Of7+Zw4ANFOJB+TIn2K3QWsgS2Ht7OU9DqZHI6qu8=
go.opentelemetry.io/otel v0.18.0/go.mod h1:PT5zQj4lTsR1YeARt8YNKcFb88/c2IKoSABK9mX0r78=
go.opentelemetry.io/otel/metric v0.18.0 h1:yuZCmY9e1ZTaMlZXLrrbAPmYW6tW1A5ozOZeOYGaTaY=
go.opentelemetry.io/otel/metric v0.18.0/go.mod h1:kEH2QtzAyBy3xDVQfGZKIcok4ZZFvd5xyKPfPcuK6pE=
go.opentelemetry.io/otel/oteltest v0.18.0 h1:FbKDFm/LnQDOHuGjED+fy3s5YMVg0z019GJ9Er66hYo=
go.opentelemetry.io/otel/oteltest v0.18.0/go.mod h1:NyierCU3/G8DLTva7KRzGii2fdxdR89zXKH1bNWY7Bo=
go.opentelemetry.io/otel/sdk v0.18.0 h1:/UiFHiJxJyEoUN2tQ6l+5f0/P01V0G9YuHeVarktRDw=
go.opentelemetry.io/otel/sdk v0.18.0/go.mod h1:nT+UdAeGQWSeTnz9vY8BBq7SEGpmWAetyo/xHUcQvxo=
go.opentelemetry.io/otel/sdk/export/metric v0.18.0 h1:0CP4KxCGeaVO2l69NNzRCULaaGiW6UGPDSF/b6gRqDs=
go.opentelemetry.io/otel/sdk/export/metric v0.18.0/go.mod h1:CFUAd+HdaQT3efTnVFYaXXp56b6bFUqkck4iRB9wu0g=
go.opentelemetry.io/otel/sdk/metric v0.18.0 h1:16ryqzWeYMl6uzwz7or3IQlCDf366Ppfm50215Mte5I=
go.opentelemetry.io/otel/sdk/metric v0.18.0/go.mod h1:NY9c56grMpjqdaYvOFon8nnsgMPBaXpde5SO1ulDyCo=
go.opentelemetry.io/otel/trace v0.18.0 h1:ilCfc/fptVKaDMK1vWk0elxpolurJbEgey9J6g6s+wk=
go.opentelemetry.io/otel/trace v0.18.0/go.mod h1:FzdUu3BPwZSZebfQ1vl5/tAa8LyMLXSJN57AXIt/iDk=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
10 changes: 6 additions & 4 deletions newrelic/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/newrelic/newrelic-telemetry-sdk-go/telemetry"
"github.com/newrelic/opentelemetry-exporter-go/newrelic"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/global"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
"go.opentelemetry.io/otel/sdk/resource"
Expand Down Expand Up @@ -40,7 +40,7 @@ func ExampleNewExporter() {
func ExampleNewExportPipeline() {
// Include environment in resource.
r := resource.NewWithAttributes(
label.String("environment", "production"),
attribute.String("environment", "production"),
semconv.ServiceNameKey.String("My Service"),
)

Expand All @@ -53,8 +53,10 @@ func ExampleNewExportPipeline() {
// Conservative sampler.
DefaultSampler: trace.ParentBased(trace.NeverSample()),
// Reduce span events.
MaxEventsPerSpan: 10,
Resource: r,
SpanLimits: trace.SpanLimits{
EventCountLimit: 10,
},
Resource: r,
}),
},
[]controller.Option{
Expand Down
8 changes: 6 additions & 2 deletions newrelic/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import (
"time"

"github.com/newrelic/newrelic-telemetry-sdk-go/telemetry"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/sdk/export/trace"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
selector "go.opentelemetry.io/otel/sdk/metric/selector/simple"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/semconv"
)

func TestServiceNameMissing(t *testing.T) {
Expand Down Expand Up @@ -165,7 +166,10 @@ func TestEndToEndTracer(t *testing.T) {
}
depth := numSpans - n
ctx, span := tracer.Start(ctx, fmt.Sprintf("Span %d", depth))
span.SetAttributes(label.Int("depth", depth))
span.SetAttributes(
attribute.Int("depth", depth),
semconv.ServiceNameKey.String(serviceName),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @akulnurislam ! This one has us scratching our heads a bit. What has changed to require us to add this serviceName in order for the test to pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RichVanderwal ya hahaha, I saw NewExporter doesn't have any setAttributes.

If I look NewExportPipeline there is set attribute serviceName for otel controller.

// Minimally default resource with a service name. This is overwritten if
// another is passed in traceOpt or pushOpt.
r := resource.NewWithAttributes(semconv.ServiceNameKey.String(service))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RichVanderwal I've changed set attribute into NewTracerProvider

)
descend(ctx, n-1)
span.End()
}
Expand Down
4 changes: 2 additions & 2 deletions newrelic/internal/transform/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"

"github.com/newrelic/newrelic-telemetry-sdk-go/telemetry"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/resource"
Expand Down Expand Up @@ -102,7 +102,7 @@ func minMaxSumCount(desc *metric.Descriptor, attrs map[string]interface{}, a agg
}, nil
}

func attributes(service string, res *resource.Resource, desc *metric.Descriptor, labels *label.Set) map[string]interface{} {
func attributes(service string, res *resource.Resource, desc *metric.Descriptor, labels *attribute.Set) map[string]interface{} {
// By default include New Relic attributes and all labels
n := 2 + labels.Len() + res.Len()
if desc != nil {
Expand Down
30 changes: 15 additions & 15 deletions newrelic/internal/transform/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"

"github.com/newrelic/newrelic-telemetry-sdk-go/telemetry"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount"
Expand Down Expand Up @@ -41,14 +41,14 @@ func TestServiceNameAttributes(t *testing.T) {
t.Errorf("service.name attribute wrong: got %q, want %q", got, want)
}

r := resource.NewWithAttributes(label.String("service.name", want))
r := resource.NewWithAttributes(attribute.String("service.name", want))
attrs = attributes(wrong, r, nil, nil)
if got, ok := attrs[serviceNameAttrKey]; !ok || got != want {
t.Errorf("service.name attribute wrong: got %q, want %q", got, want)
}

r = resource.NewWithAttributes(label.String("service.name", wrong))
l := label.NewSet(label.String("service.name", want))
r = resource.NewWithAttributes(attribute.String("service.name", wrong))
l := attribute.NewSet(attribute.String("service.name", want))
attrs = attributes(wrong, r, nil, &l)
if got, ok := attrs[serviceNameAttrKey]; !ok || got != want {
t.Errorf("service.name attribute wrong: got %q, want %q", got, want)
Expand All @@ -59,20 +59,20 @@ func TestAttributes(t *testing.T) {
for i, test := range []struct {
res *resource.Resource
opts []metric.InstrumentOption
labels []label.KeyValue
labels []attribute.KeyValue
want map[string]interface{}
}{
{}, // test defaults
{
res: resource.NewWithAttributes(label.String("A", "a")),
res: resource.NewWithAttributes(attribute.String("A", "a")),
opts: nil,
labels: nil,
want: map[string]interface{}{
"A": "a",
},
},
{
res: resource.NewWithAttributes(label.String("A", "a"), label.Int64("1", 1)),
res: resource.NewWithAttributes(attribute.String("A", "a"), attribute.Int64("1", 1)),
opts: nil,
labels: nil,
want: map[string]interface{}{
Expand All @@ -99,27 +99,27 @@ func TestAttributes(t *testing.T) {
{
res: nil,
opts: nil,
labels: []label.KeyValue{label.String("A", "a")},
labels: []attribute.KeyValue{attribute.String("A", "a")},
want: map[string]interface{}{
"A": "a",
},
},
{
res: nil,
opts: nil,
labels: []label.KeyValue{label.String("A", "a"), label.Int64("1", 1)},
labels: []attribute.KeyValue{attribute.String("A", "a"), attribute.Int64("1", 1)},
want: map[string]interface{}{
"A": "a",
"1": int64(1),
},
},
{
res: resource.NewWithAttributes(label.String("K1", "V1"), label.String("K2", "V2")),
res: resource.NewWithAttributes(attribute.String("K1", "V1"), attribute.String("K2", "V2")),
opts: []metric.InstrumentOption{
metric.WithUnit(unit.Milliseconds),
metric.WithDescription("d3"),
},
labels: []label.KeyValue{label.String("K2", "V3")},
labels: []attribute.KeyValue{attribute.String("K2", "V3")},
want: map[string]interface{}{
"K1": "V1",
"K2": "V3",
Expand All @@ -130,7 +130,7 @@ func TestAttributes(t *testing.T) {
} {
name := fmt.Sprintf("descriptor test %d", i)
desc := metric.NewDescriptor(name, metric.CounterInstrumentKind, number.Int64Kind, test.opts...)
l := label.NewSet(test.labels...)
l := attribute.NewSet(test.labels...)
expected := make(map[string]interface{}, len(defaultAttrs)+len(test.want))
for k, v := range defaultAttrs {
expected[k] = v
Expand All @@ -149,7 +149,7 @@ var numKinds = []number.Kind{number.Int64Kind, number.Float64Kind}

func TestMinMaxSumCountRecord(t *testing.T) {
name := "test-mmsc"
l := label.NewSet()
l := attribute.NewSet()
for _, iKind := range []metric.InstrumentKind{metric.ValueRecorderInstrumentKind, metric.ValueObserverInstrumentKind} {
for _, nKind := range numKinds {
desc := metric.NewDescriptor(name, iKind, nKind)
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestMinMaxSumCountRecord(t *testing.T) {

func TestSumRecord(t *testing.T) {
name := "test-sum"
l := label.NewSet()
l := attribute.NewSet()
for _, nKind := range numKinds {
desc := metric.NewDescriptor(name, metric.CounterInstrumentKind, nKind)
s := sumAgg.New(1)[0]
Expand Down Expand Up @@ -255,7 +255,7 @@ func (a fakeAgg) Merge(metricsdk.Aggregator, *metric.Descriptor) error
func TestErrUnimplementedAgg(t *testing.T) {
fa := fakeAgg{}
desc := metric.NewDescriptor("", metric.CounterInstrumentKind, number.Int64Kind)
l := label.NewSet()
l := attribute.NewSet()
_, err := Record("", metricsdk.NewRecord(&desc, &l, nil, fa, time.Now(), time.Now()))
if !errors.Is(err, ErrUnimplementedAgg) {
t.Errorf("unexpected error: %v", err)
Expand Down
44 changes: 17 additions & 27 deletions newrelic/internal/transform/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"time"

"github.com/newrelic/newrelic-telemetry-sdk-go/telemetry"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
exporttrace "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -124,17 +124,12 @@ func TestTransformSpans(t *testing.T) {
StartTime: now,
EndTime: now.Add(2 * time.Second),
Name: "mySpan",
Attributes: []label.KeyValue{
label.Bool("x0", true),
label.Float32("x1", 1.0),
label.Float64("x2", 2.0),
label.Int("x3", 3),
label.Int32("x4", 4),
label.Int64("x5", 5),
label.String("x6", "6"),
label.Uint("x7", 7),
label.Uint32("x8", 8),
label.Uint64("x9", 9),
Attributes: []attribute.KeyValue{
attribute.Bool("x0", true),
attribute.Float64("x1", 1.0),
attribute.Int("x2", 2),
attribute.Int64("x3", 3),
attribute.String("x4", "4"),
},
},
expect: telemetry.Span{
Expand All @@ -146,15 +141,10 @@ func TestTransformSpans(t *testing.T) {
ServiceName: service,
Attributes: map[string]interface{}{
"x0": true,
"x1": float32(1.0),
"x2": float64(2.0),
"x1": float64(1.0),
"x2": int64(2),
"x3": int64(3),
"x4": int32(4),
"x5": int64(5),
"x6": "6",
"x7": uint64(7),
"x8": uint32(8),
"x9": uint64(9),
"x4": "4",
instrumentationProviderAttrKey: instrumentationProviderAttrValue,
collectorNameAttrKey: collectorNameAttrValue,
},
Expand All @@ -172,8 +162,8 @@ func TestTransformSpans(t *testing.T) {
StartTime: now,
EndTime: now.Add(2 * time.Second),
Name: "mySpan",
Attributes: []label.KeyValue{
label.Bool("x0", true),
Attributes: []attribute.KeyValue{
attribute.Bool("x0", true),
},
},
expect: telemetry.Span{
Expand Down Expand Up @@ -203,7 +193,7 @@ func TestTransformSpans(t *testing.T) {
EndTime: now.Add(2 * time.Second),
Name: "mySpan",
Resource: resource.NewWithAttributes(
label.String("service.name", "resource service"),
attribute.String("service.name", "resource service"),
),
},
expect: telemetry.Span{
Expand Down Expand Up @@ -232,7 +222,7 @@ func TestTransformSpans(t *testing.T) {
EndTime: now.Add(2 * time.Second),
Name: "mySpan",
Resource: resource.NewWithAttributes(
label.String("service.name", "resource service"),
attribute.String("service.name", "resource service"),
),
},
expect: telemetry.Span{
Expand Down Expand Up @@ -261,10 +251,10 @@ func TestTransformSpans(t *testing.T) {
EndTime: now.Add(2 * time.Second),
Name: "mySpan",
Resource: resource.NewWithAttributes(
label.String("service.name", "resource service"),
attribute.String("service.name", "resource service"),
),
Attributes: []label.KeyValue{
label.String("service.name", "attributes service"),
Attributes: []attribute.KeyValue{
attribute.String("service.name", "attributes service"),
},
},
expect: telemetry.Span{
Expand Down