Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(attributes) bump semconv to 1.26.0 #6172

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
95348f2
otelmongo#6171 bump semconv to 1.26.0
prestonvasquez Oct 1, 2024
f7449ef
Merge branch 'main' into otelmongo#6171
prestonvasquez Oct 1, 2024
e075e01
otelmongo#6171 update changelog
prestonvasquez Oct 1, 2024
c863b33
Merge branch 'otelmongo#6171' of github.com:prestonvasquez/openteleme…
prestonvasquez Oct 1, 2024
6b5056e
Merge branch 'main' into otelmongo#6171
prestonvasquez Oct 2, 2024
3db421e
otelmongo#6171 Add semconv registry
prestonvasquez Oct 3, 2024
a2bc652
Merge branch 'otelmongo#6171' of github.com:prestonvasquez/openteleme…
prestonvasquez Oct 3, 2024
2eef3fe
otelmongo#6171 Specify generic types
prestonvasquez Oct 4, 2024
aaa6129
otelmongo#6171 Remove profiling files
prestonvasquez Oct 4, 2024
bf676a1
Update CHANGELOG.md
prestonvasquez Oct 4, 2024
c5b3f3c
otelmongo#6171 clean up tests
prestonvasquez Oct 4, 2024
d0ec780
Merge branch 'otelmongo#6171' of github.com:prestonvasquez/openteleme…
prestonvasquez Oct 4, 2024
b42dac7
otelmongo#6171 Resolve merge conflicts
prestonvasquez Oct 4, 2024
9aed9c9
otelmongo#6171 udpate changelog
prestonvasquez Oct 4, 2024
00ad843
otelmongo#6171 use goimports to format testfile
prestonvasquez Oct 4, 2024
6ebd6d2
otelmongo#6171 Run precommit
prestonvasquez Oct 4, 2024
91a4e29
Remove registry pattern
prestonvasquez Nov 13, 2024
d7f792f
Update docs and changelog
prestonvasquez Nov 13, 2024
fd6c1f6
Remove version
prestonvasquez Nov 13, 2024
b140c55
Add license
prestonvasquez Nov 13, 2024
3fd3835
Merge main
prestonvasquez Nov 13, 2024
3777228
Use switch statement for tcp
prestonvasquez Nov 13, 2024
e9b22bd
Merge branch 'main' into otelmongo#6171
prestonvasquez Nov 19, 2024
39b5893
Move CHANGELOG
prestonvasquez Nov 19, 2024
6de6ad5
run precommit
prestonvasquez Nov 19, 2024
e9173c7
Resolve merge conflicts
prestonvasquez Dec 30, 2024
9d062b7
otelmongo#6171 Migrate to semconv pkg pattern
prestonvasquez Dec 30, 2024
94788c2
otelmongo#6171 Resolve merge conflicts
prestonvasquez Dec 30, 2024
3b7f9a2
Update CHANGELOG
prestonvasquez Dec 30, 2024
6dd8e88
Fix typos and wrap comments at 80
prestonvasquez Dec 30, 2024
6a7d4ce
Add licenses to semconv files
prestonvasquez Jan 2, 2025
cc503cb
Resolve linting issues
prestonvasquez Jan 3, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed

- The function signature of `NewLogProcessor` in `go.opentelemetry.io/contrib/processors/minsev` has changed to accept the added `Severitier` interface instead of a `log.Severity`. (#6116)
- Attributes for otelmongo will change to reflect [semconv/v1.26.0](https://github.com/open-telemetry/opentelemetry-go/pull/5476). `db.operation` will change to `db.operation.name`, `db.name` will change to `db.namespace`, `net.peer.port` will change to `network.peer.port`, `net.transport` will change to `network.transport`, and `db.statement` will change to `db.query.text`.
prestonvasquez marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ package otelmongo // import "go.opentelemetry.io/contrib/instrumentation/go.mong
import (
"context"
"fmt"
"net"
"strconv"
"strings"
"sync"

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

"go.mongodb.org/mongo-driver/bson"
Expand All @@ -37,18 +38,18 @@ func (m *monitor) Started(ctx context.Context, evt *event.CommandStartedEvent) {

attrs := []attribute.KeyValue{
semconv.DBSystemMongoDB,
semconv.DBOperation(evt.CommandName),
semconv.DBName(evt.DatabaseName),
semconv.NetPeerName(hostname),
semconv.NetPeerPort(port),
semconv.NetTransportTCP,
semconv.DBOperationName(evt.CommandName),
semconv.DBNamespace(evt.DatabaseName),
semconv.NetworkPeerAddress(net.JoinHostPort(hostname, strconv.Itoa(port))),
semconv.NetworkPeerPort(port),
semconv.NetworkTransportTCP,
}
if !m.cfg.CommandAttributeDisabled {
attrs = append(attrs, semconv.DBStatement(sanitizeCommand(evt.Command)))
attrs = append(attrs, semconv.DBQueryText(sanitizeCommand(evt.Command)))
}
if collection, err := extractCollection(evt); err == nil && collection != "" {
spanName = collection + "."
attrs = append(attrs, semconv.DBMongoDBCollection(collection))
attrs = append(attrs, semconv.DBCollectionName(collection))
}
spanName += evt.CommandName
opts := []trace.SpanStartOption{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func TestDBCrudOperation(t *testing.T) {
return assert.Equal(t, "test-collection.insert", s.Name(), "expected %s", s.Name())
},
func(s sdktrace.ReadOnlySpan) bool {
return assert.Contains(t, s.Attributes(), attribute.String("db.operation", "insert"))
return assert.Contains(t, s.Attributes(), attribute.String("db.operation.name", "insert"))
},
func(s sdktrace.ReadOnlySpan) bool {
return assert.Contains(t, s.Attributes(), attribute.String("db.mongodb.collection", "test-collection"))
return assert.Contains(t, s.Attributes(), attribute.String("db.collection.name", "test-collection"))
},
func(s sdktrace.ReadOnlySpan) bool {
return assert.Equal(t, codes.Unset, s.Status().Code)
Expand All @@ -56,7 +56,7 @@ func TestDBCrudOperation(t *testing.T) {
excludeCommand: false,
validators: append(commonValidators, func(s sdktrace.ReadOnlySpan) bool {
for _, attr := range s.Attributes() {
if attr.Key == "db.statement" {
if attr.Key == "db.query.text" {
return assert.Contains(t, attr.Value.AsString(), `"test-item":"test-value"`)
}
}
Expand All @@ -72,7 +72,7 @@ func TestDBCrudOperation(t *testing.T) {
excludeCommand: true,
validators: append(commonValidators, func(s sdktrace.ReadOnlySpan) bool {
for _, attr := range s.Attributes() {
if attr.Key == "db.statement" {
if attr.Key == "db.query.text" {
return false
}
}
Expand Down Expand Up @@ -131,10 +131,10 @@ func TestDBCrudOperation(t *testing.T) {
assert.Equal(mt, trace.SpanKindClient, s.SpanKind())
attrs := s.Attributes()
assert.Contains(mt, attrs, attribute.String("db.system", "mongodb"))
assert.Contains(mt, attrs, attribute.String("net.peer.name", "<mock_connection>"))
assert.Contains(mt, attrs, attribute.Int64("net.peer.port", int64(27017)))
assert.Contains(mt, attrs, attribute.String("net.transport", "ip_tcp"))
assert.Contains(mt, attrs, attribute.String("db.name", "test-database"))
assert.Contains(mt, attrs, attribute.String("network.peer.address", "<mock_connection>:27017"))
assert.Contains(mt, attrs, attribute.Int64("network.peer.port", int64(27017)))
assert.Contains(mt, attrs, attribute.String("network.transport", "tcp"))
assert.Contains(mt, attrs, attribute.String("db.namespace", "test-database"))
for _, v := range tc.validators {
assert.True(mt, v(s))
}
Expand All @@ -160,10 +160,10 @@ func TestDBCollectionAttribute(t *testing.T) {
return assert.Equal(t, "test-collection.delete", s.Name())
},
func(s sdktrace.ReadOnlySpan) bool {
return assert.Contains(t, s.Attributes(), attribute.String("db.operation", "delete"))
return assert.Contains(t, s.Attributes(), attribute.String("db.operation.name", "delete"))
},
func(s sdktrace.ReadOnlySpan) bool {
return assert.Contains(t, s.Attributes(), attribute.String("db.mongodb.collection", "test-collection"))
return assert.Contains(t, s.Attributes(), attribute.String("db.collection.name", "test-collection"))
},
func(s sdktrace.ReadOnlySpan) bool {
return assert.Equal(t, codes.Unset, s.Status().Code)
Expand All @@ -186,7 +186,7 @@ func TestDBCollectionAttribute(t *testing.T) {
return assert.Equal(t, "listCollections", s.Name())
},
func(s sdktrace.ReadOnlySpan) bool {
return assert.Contains(t, s.Attributes(), attribute.String("db.operation", "listCollections"))
return assert.Contains(t, s.Attributes(), attribute.String("db.operation.name", "listCollections"))
},
func(s sdktrace.ReadOnlySpan) bool {
return assert.Equal(t, codes.Unset, s.Status().Code)
Expand Down Expand Up @@ -238,10 +238,10 @@ func TestDBCollectionAttribute(t *testing.T) {
assert.Equal(mt, trace.SpanKindClient, s.SpanKind())
attrs := s.Attributes()
assert.Contains(mt, attrs, attribute.String("db.system", "mongodb"))
assert.Contains(mt, attrs, attribute.String("net.peer.name", "<mock_connection>"))
assert.Contains(mt, attrs, attribute.Int64("net.peer.port", int64(27017)))
assert.Contains(mt, attrs, attribute.String("net.transport", "ip_tcp"))
assert.Contains(mt, attrs, attribute.String("db.name", "test-database"))
assert.Contains(mt, attrs, attribute.String("network.peer.address", "<mock_connection>:27017"))
assert.Contains(mt, attrs, attribute.Int64("network.peer.port", int64(27017)))
assert.Contains(mt, attrs, attribute.String("network.transport", "tcp"))
assert.Contains(mt, attrs, attribute.String("db.namespace", "test-database"))
for _, v := range tc.validators {
assert.True(mt, v(s))
}
Expand Down
Loading