Skip to content

Commit

Permalink
Update to semconv v1.17.0 (#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias authored Feb 1, 2023
1 parent 824d1c1 commit 12ee32b
Show file tree
Hide file tree
Showing 49 changed files with 218 additions and 127 deletions.
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ This upgrades [OpenTelemetry Go to v1.12.0/v0.35.0][otel-v1.12.0] and
`github.com/signalfx/splunk-otel-go/instrumentation/database/sql/splunksql`
is no longer orphaned. (#1682)

### Added

- The `NetSockFamily` type and related variables to be use in the
`ConnectionConfig` from
`github.com/signalfx/splunk-otel-go/instrumentation/database/sql/splunksql`.
(#1749)

### Changed

- Add the `NetSockFamily` field to the `ConnectionConfig` in
`github.com/signalfx/splunk-otel-go/instrumentation/database/sql/splunksql`.
This is used to define the protocol address family used for communication with
the database. (#1749)
- Update `go.opentelemetry.io/otel/semconv` to `v1.17.0` in the following
packages. (#1749)
- `github.com/signalfx/splunk-otel-go/distro`
- `github.com/signalfx/splunk-otel-go/instrumentation/database/sql/splunksql`
- `github.com/signalfx/splunk-otel-go/instrumentation/github.com/confluentinc/confluent-kafka-go/kafka/splunkkafka`
- `github.com/signalfx/splunk-otel-go/instrumentation/github.com/go-chi/chi/splunkchi`
- `github.com/signalfx/splunk-otel-go/instrumentation/github.com/go-sql-driver/mysql/splunkmysql`
- `github.com/signalfx/splunk-otel-go/instrumentation/github.com/gomodule/redigo/splunkredigo`
- `github.com/signalfx/splunk-otel-go/instrumentation/github.com/jackc/pgx/splunkpgx`
- `github.com/signalfx/splunk-otel-go/instrumentation/github.com/jackc/pgx/splunkpgx`
- `github.com/signalfx/splunk-otel-go/instrumentation/github.com/syndtr/goleveldb/leveldb/splunkleveldb`
- `github.com/signalfx/splunk-otel-go/instrumentation/github.com/tidwall/buntdb/splunkbuntdb`
- `github.com/signalfx/splunk-otel-go/instrumentation/gopkg.in/olivere/elastic/splunkelastic`
- `github.com/signalfx/splunk-otel-go/instrumentation/k8s.io/client-go/splunkclient-go`

### Deprecated

- The `NetTransportIP` and `NetTransportUnix` variables from
`github.com/signalfx/splunk-otel-go/instrumentation/database/sql/splunksql`
are deprecated as they are no longer available in `go.opentelemetry.io/otel/semconv/v1.17.0`.
Use an appropriate `NetSockFamily*` variable instead. (#1749)

## [1.2.0] - 2023-01-11

This upgrades [OpenTelemetry Go to v1.11.2/v0.34.0][otel-v1.11.2] and
Expand Down
2 changes: 1 addition & 1 deletion distro/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"

splunkotel "github.com/signalfx/splunk-otel-go"
)
Expand Down
19 changes: 14 additions & 5 deletions instrumentation/database/sql/splunksql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"

"github.com/signalfx/splunk-otel-go/instrumentation/database/sql/splunksql/internal/moniker"
Expand Down Expand Up @@ -172,6 +172,9 @@ type ConnectionConfig struct {
Port int
// NetTransport is the transport protocol used to connect to the database.
NetTransport NetTransport
// NetSockFamily is the protocol address family used for communication to
// the database.
NetSockFamily NetSockFamily
}

// Attributes returns the connection settings as attributes compliant with
Expand All @@ -192,17 +195,23 @@ func (c ConnectionConfig) Attributes() ([]attribute.KeyValue, error) { //nolint:
}
if c.Host != "" {
if ip := net.ParseIP(c.Host); ip != nil {
attrs = append(attrs, semconv.NetPeerIPKey.String(ip.String()))
attrs = append(attrs, semconv.NetSockPeerAddrKey.String(ip.String()))
if c.Port > 0 {
attrs = append(attrs, semconv.NetSockPeerPortKey.Int(c.Port))
}
} else {
attrs = append(attrs, semconv.NetPeerNameKey.String(c.Host))
if c.Port > 0 {
attrs = append(attrs, semconv.NetPeerPortKey.Int(c.Port))
}
}
} else {
errs = append(errs, "missing required peer IP or hostname")
}
if c.Port > 0 {
attrs = append(attrs, semconv.NetPeerPortKey.Int(c.Port))
}
attrs = append(attrs, c.NetTransport.Attribute())
if a := c.NetSockFamily.Attribute(); a.Key.Defined() {
attrs = append(attrs, a)
}

var err error
if len(errs) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/database/sql/splunksql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"database/sql/driver"
"errors"

semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"

"github.com/signalfx/splunk-otel-go/instrumentation/database/sql/splunksql/internal/moniker"
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/database/sql/splunksql/dbsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package splunksql

import (
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
)

// DBSystem is a database system type.
Expand Down
3 changes: 2 additions & 1 deletion instrumentation/database/sql/splunksql/example_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func ExampleRegister() {
User: user,
Host: host,
Port: 9876,
NetTransport: splunksql.NetTransportIP,
NetTransport: splunksql.NetTransportTCP,
NetSockFamily: splunksql.NetSockFamilyInet,
}, nil
},
})
Expand Down
4 changes: 2 additions & 2 deletions instrumentation/database/sql/splunksql/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"log"

"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"

"github.com/signalfx/splunk-otel-go/instrumentation/database/sql/splunksql"
)
Expand All @@ -43,7 +43,7 @@ var (
// Do not include passwords!
semconv.DBConnectionStringKey.String(sanitized),
semconv.DBUserKey.String(user),
// Use semconv.NetPeerIPKey if connecting via an IP address. If
// Use semconv.NetSockPeerAddrKey if connecting via an IP address. If
// connecting via a Unix socket, use this attribute key.
semconv.NetPeerNameKey.String(host),
semconv.NetPeerPortKey.Int(port),
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/database/sql/splunksql/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"database/sql/driver"

semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"

"github.com/signalfx/splunk-otel-go/instrumentation/database/sql/splunksql/internal/moniker"
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/database/sql/splunksql/test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
traceapi "go.opentelemetry.io/otel/trace"

"github.com/signalfx/splunk-otel-go/instrumentation/database/sql/splunksql"
Expand Down
33 changes: 28 additions & 5 deletions instrumentation/database/sql/splunksql/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,51 @@ package splunksql

import (
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
)

// NetTransport is a communication transport protocol.
type NetTransport attribute.KeyValue

// Attribute returns t as an attribute KeyValue. If t is empty the returned
// attribute will default to a NetTransportOther.
// Attribute returns t as an attribute KeyValue. If t is empty or a deprecated
// value, the returned attribute will default to a NetTransportOther.
func (t NetTransport) Attribute() attribute.KeyValue {
if !t.Key.Defined() {
return semconv.NetTransportOther
}
switch t {
case NetTransportIP, NetTransportUnix:
return semconv.NetTransportOther
}
return attribute.KeyValue(t)
}

// Valid transport protocols.
var (
NetTransportTCP = NetTransport(semconv.NetTransportTCP)
NetTransportUDP = NetTransport(semconv.NetTransportUDP)
NetTransportIP = NetTransport(semconv.NetTransportIP)
NetTransportUnix = NetTransport(semconv.NetTransportUnix)
NetTransportPipe = NetTransport(semconv.NetTransportPipe)
NetTransportInProc = NetTransport(semconv.NetTransportInProc)
NetTransportOther = NetTransport(semconv.NetTransportOther)

// Deprecated: Use appropriate NetSockFamily* instead.
NetTransportIP = NetTransport(semconv.NetTransportKey.String("ip"))
// Deprecated: Use appropriate NetSockFamily* instead.
NetTransportUnix = NetTransport(semconv.NetTransportKey.String("unix"))
)

// NetSockFamily is a protocol address family used for communication.
type NetSockFamily attribute.KeyValue

// Attribute returns t as an attribute KeyValue. If s is empty the returned
// attribute will also be an empty, undefined, KeyValue.
func (s NetSockFamily) Attribute() attribute.KeyValue {
return attribute.KeyValue(s)
}

// Valid protocol address families.
var (
NetSockFamilyInet = NetSockFamily(semconv.NetSockFamilyInet)
NetSockFamilyInet6 = NetSockFamily(semconv.NetSockFamilyInet6)
NetSockFamilyUnix = NetSockFamily(semconv.NetSockFamilyUnix)
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package splunkkafka
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"

"github.com/signalfx/splunk-otel-go/instrumentation/internal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

"github.com/confluentinc/confluent-kafka-go/kafka"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"

"github.com/signalfx/splunk-otel-go/instrumentation/internal"
Expand Down Expand Up @@ -149,10 +149,10 @@ func (c *Consumer) startSpan(msg *kafka.Message) consumerSpan {
offset := strconv.FormatInt(int64(msg.TopicPartition.Offset), base10)
opts := c.cfg.MergedSpanStartOptions(
trace.WithAttributes(
semconv.MessagingDestinationKey.String(*msg.TopicPartition.Topic),
semconv.MessagingSourceNameKey.String(*msg.TopicPartition.Topic),
semconv.MessagingMessageIDKey.String(offset),
semconv.MessagingKafkaMessageKeyKey.String(string(msg.Key)),
semconv.MessagingKafkaPartitionKey.Int64(int64(msg.TopicPartition.Partition)),
semconv.MessagingKafkaSourcePartitionKey.Int64(int64(msg.TopicPartition.Partition)),
),
trace.WithSpanKind(trace.SpanKindConsumer),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -165,12 +165,12 @@ func TestConsumerSpan(t *testing.T) {
assert.Contains(t, attrs, semconv.MessagingSystemKey.String("kafka"))
assert.Contains(t, attrs, commonAttr)
assert.Contains(t, attrs, semconv.MessagingDestinationKindTopic)
assert.Contains(t, attrs, semconv.MessagingDestinationKey.String(testTopic))
assert.Contains(t, attrs, semconv.MessagingSourceNameKey.String(testTopic))
assert.Contains(t, attrs, semconv.MessagingOperationReceive)
assert.Contains(t, attrs, semconv.MessagingMessageIDKey.String("1"))
assert.Contains(t, attrs, semconv.MessagingKafkaMessageKeyKey.String(keys[i]))
assert.Contains(t, attrs, semconv.MessagingKafkaConsumerGroupKey.String(grpID))
assert.Contains(t, attrs, semconv.MessagingKafkaPartitionKey.Int64(1))
assert.Contains(t, attrs, semconv.MessagingKafkaSourcePartitionKey.Int64(1))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"github.com/confluentinc/confluent-kafka-go/kafka"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"

"github.com/signalfx/splunk-otel-go/instrumentation/internal"
Expand Down Expand Up @@ -97,10 +97,10 @@ func (p *Producer) startSpan(msg *kafka.Message) trace.Span {
offset := strconv.FormatInt(int64(msg.TopicPartition.Offset), base10)
opts := p.cfg.MergedSpanStartOptions(
trace.WithAttributes(
semconv.MessagingDestinationKey.String(*msg.TopicPartition.Topic),
semconv.MessagingDestinationNameKey.String(*msg.TopicPartition.Topic),
semconv.MessagingMessageIDKey.String(offset),
semconv.MessagingKafkaMessageKeyKey.String(string(msg.Key)),
semconv.MessagingKafkaPartitionKey.Int64(int64(msg.TopicPartition.Partition)),
semconv.MessagingKafkaDestinationPartitionKey.Int64(int64(msg.TopicPartition.Partition)),
),
trace.WithSpanKind(trace.SpanKindProducer),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -110,10 +110,10 @@ func TestProducerChannelSpan(t *testing.T) {
attrs := record.SpanConfig.Attributes()
assert.Contains(t, attrs, semconv.MessagingSystemKey.String("kafka"))
assert.Contains(t, attrs, semconv.MessagingDestinationKindTopic)
assert.Contains(t, attrs, semconv.MessagingDestinationKey.String(testTopic))
assert.Contains(t, attrs, semconv.MessagingDestinationNameKey.String(testTopic))
assert.Contains(t, attrs, semconv.MessagingMessageIDKey.String("1"))
assert.Contains(t, attrs, semconv.MessagingKafkaMessageKeyKey.String(keys[i]))
assert.Contains(t, attrs, semconv.MessagingKafkaPartitionKey.Int64(1))
assert.Contains(t, attrs, semconv.MessagingKafkaDestinationPartitionKey.Int64(1))
}
}

Expand Down Expand Up @@ -169,9 +169,9 @@ func TestProduceSpan(t *testing.T) {
assert.Contains(t, attrs, semconv.MessagingSystemKey.String("kafka"))
assert.Contains(t, attrs, commonAttr)
assert.Contains(t, attrs, semconv.MessagingDestinationKindTopic)
assert.Contains(t, attrs, semconv.MessagingDestinationKey.String(testTopic))
assert.Contains(t, attrs, semconv.MessagingDestinationNameKey.String(testTopic))
assert.Contains(t, attrs, semconv.MessagingMessageIDKey.String("1"))
assert.Contains(t, attrs, semconv.MessagingKafkaMessageKeyKey.String(keys[i]))
assert.Contains(t, attrs, semconv.MessagingKafkaPartitionKey.Int64(1))
assert.Contains(t, attrs, semconv.MessagingKafkaDestinationPartitionKey.Int64(1))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
traceapi "go.opentelemetry.io/otel/trace"
"go.uber.org/goleak"

Expand Down Expand Up @@ -308,10 +308,10 @@ func assertProducerSpan(t *testing.T, span trace.ReadOnlySpan) {
attrs := span.Attributes()
assert.Contains(t, attrs, semconv.MessagingSystemKey.String("kafka"))
assert.Contains(t, attrs, semconv.MessagingDestinationKindTopic)
assert.Contains(t, attrs, semconv.MessagingDestinationKey.String(testTopic))
assert.Contains(t, attrs, semconv.MessagingDestinationNameKey.String(testTopic))
assert.Contains(t, attrs, semconv.MessagingMessageIDKey.String("0"))
assert.Contains(t, attrs, semconv.MessagingKafkaMessageKeyKey.String(string(key)))
assert.Contains(t, attrs, semconv.MessagingKafkaPartitionKey.Int64(0))
assert.Contains(t, attrs, semconv.MessagingKafkaDestinationPartitionKey.Int64(0))
}

func assertConsumerSpan(t *testing.T, span trace.ReadOnlySpan) {
Expand All @@ -320,11 +320,11 @@ func assertConsumerSpan(t *testing.T, span trace.ReadOnlySpan) {
attrs := span.Attributes()
assert.Contains(t, attrs, semconv.MessagingSystemKey.String("kafka"))
assert.Contains(t, attrs, semconv.MessagingDestinationKindTopic)
assert.Contains(t, attrs, semconv.MessagingDestinationKey.String(testTopic))
assert.Contains(t, attrs, semconv.MessagingSourceNameKey.String(testTopic))
assert.Contains(t, attrs, semconv.MessagingOperationReceive)
assert.Contains(t, attrs, semconv.MessagingKafkaConsumerGroupKey.String(testGroupID))
assert.Contains(t, attrs, semconv.MessagingKafkaMessageKeyKey.String(string(key)))
assert.Contains(t, attrs, semconv.MessagingKafkaPartitionKey.Int64(0))
assert.Contains(t, attrs, semconv.MessagingKafkaSourcePartitionKey.Int64(0))
}

func requireEventIsMessage(t *testing.T, e kafka.Event) *kafka.Message {
Expand Down
Loading

0 comments on commit 12ee32b

Please sign in to comment.