Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Update `http.route` attribute to support `request.Pattern` in `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux`. (#7108)
- Change the default span name to be `GET /path` so it complies with the HTTP semantic conventions in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`. (#6381)
- Set `url.scheme` attribute to the request URL.Scheme when possible for HTTP client metrics in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#6938)
- The semantic conventions have been upgraded from `v1.17.0` to `v1.30.0` in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#7270)
- All `net.peer.*` and `net.host.*` attributes are now set to correct `server.*` attributes.
- No `net.socket.*` attributes are set.

### Fixed

Expand Down Expand Up @@ -98,6 +101,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The deprecated `SemVersion` function is removed in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/test`, use `Version` function instead. (#7143)
- The deprecated `SQSAttributeSetter` function is removed in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws` package, use `SQSAttributeBuilder` instead. (#7145)
- The deprecated `SemVersion` function is removed in `go.opentelemetry.io/contrib/instrumentation/host` package, use `Version` instead. (#7203)
- The `GRPCStatusCodeKey` constant from `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` is removed.
Use `semconv.RPCGRPCStatusCodeKey` from `go.opentelemetry.io/otel/semconv/*` instead. (#7270)

<!-- Released section -->
<!-- Don't change this section unless doing release -->
Expand Down
8 changes: 2 additions & 6 deletions instrumentation/google.golang.org/grpc/otelgrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ import (
"go.opentelemetry.io/otel/trace"
)

const (
// ScopeName is the instrumentation scope name.
ScopeName = "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
// GRPCStatusCodeKey is convention for numeric status code of a gRPC request.
GRPCStatusCodeKey = attribute.Key("rpc.grpc.status_code")
Comment thread
MrAlias marked this conversation as resolved.
)
// ScopeName is the instrumentation scope name.
const ScopeName = "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"

// InterceptorFilter is a predicate used to determine whether a given request in
// interceptor info should be instrumented. A InterceptorFilter must return true if
Expand Down
54 changes: 20 additions & 34 deletions instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal"
"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.30.0"
"go.opentelemetry.io/otel/trace"
)

Expand All @@ -37,13 +37,13 @@
}
span.AddEvent("message", trace.WithAttributes(
attribute.KeyValue(m),
RPCMessageIDKey.Int(id),
semconv.RPCMessageIDKey.Int(id),
))
}

var (
messageSent = messageType(RPCMessageTypeSent)
messageReceived = messageType(RPCMessageTypeReceived)
messageSent = messageType(semconv.RPCMessageTypeSent)
messageReceived = messageType(semconv.RPCMessageTypeReceived)
)

// clientStream wraps around the embedded grpc.ClientStream, and intercepts the RecvMsg and
Expand Down Expand Up @@ -305,46 +305,32 @@

// telemetryAttributes returns a span name and span and metric attributes from
// the gRPC method and peer address.
func telemetryAttributes(fullMethod, peerAddress string) (string, []attribute.KeyValue) {
func telemetryAttributes(fullMethod, sererAddr string) (string, []attribute.KeyValue) {
name, methodAttrs := internal.ParseFullMethod(fullMethod)
peerAttrs := peerAttr(peerAddress)
srvAttrs := serverAddrAttrs(sererAddr)

attrs := make([]attribute.KeyValue, 0, 1+len(methodAttrs)+len(peerAttrs))
attrs = append(attrs, RPCSystemGRPC)
attrs := make([]attribute.KeyValue, 0, 1+len(methodAttrs)+len(srvAttrs))
attrs = append(attrs, semconv.RPCSystemGRPC)
attrs = append(attrs, methodAttrs...)
attrs = append(attrs, peerAttrs...)
attrs = append(attrs, srvAttrs...)
return name, attrs
}

// peerAttr returns attributes about the peer address.
func peerAttr(addr string) []attribute.KeyValue {
host, p, err := net.SplitHostPort(addr)
// serverAddrAttrs returns the server address attributes for the hostport.
func serverAddrAttrs(hostport string) []attribute.KeyValue {
h, pStr, err := net.SplitHostPort(hostport)
if err != nil {
return nil
// The server.address attribute is required.
return []attribute.KeyValue{semconv.ServerAddress(hostport)}
}

if host == "" {
host = "127.0.0.1"
}
port, err := strconv.Atoi(p)
p, err := strconv.Atoi(pStr)
if err != nil {
return nil
return []attribute.KeyValue{semconv.ServerAddress(h)}

Check warning on line 328 in instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go

View check run for this annotation

Codecov / codecov/patch

instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go#L328

Added line #L328 was not covered by tests
}

var attr []attribute.KeyValue
if ip := net.ParseIP(host); ip != nil {
attr = []attribute.KeyValue{
semconv.NetSockPeerAddr(host),
semconv.NetSockPeerPort(port),
}
} else {
attr = []attribute.KeyValue{
semconv.NetPeerName(host),
semconv.NetPeerPort(port),
}
return []attribute.KeyValue{
semconv.ServerAddress(h),
semconv.ServerPort(p),
}

return attr
}

// peerFromCtx returns a peer address from a context, if one exists.
Expand All @@ -358,7 +344,7 @@

// statusCodeAttr returns status code attribute based on given gRPC code.
func statusCodeAttr(c grpc_codes.Code) attribute.KeyValue {
return GRPCStatusCodeKey.Int64(int64(c))
return semconv.RPCGRPCStatusCodeKey.Int64(int64(c))
}

// serverStatus returns a span status code and message for a given gRPC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
semconv "go.opentelemetry.io/otel/semconv/v1.30.0"
)

// ParseFullMethod returns a span name following the OpenTelemetry semantic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

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

"github.com/stretchr/testify/assert"
)
Expand Down
41 changes: 0 additions & 41 deletions instrumentation/google.golang.org/grpc/otelgrpc/semconv.go

This file was deleted.

84 changes: 42 additions & 42 deletions instrumentation/google.golang.org/grpc/otelgrpc/stats_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
semconv "go.opentelemetry.io/otel/semconv/v1.30.0"
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal"
Expand Down Expand Up @@ -63,9 +63,9 @@ func NewServerHandler(opts ...Option) stats.Handler {

var err error
h.duration, err = meter.Float64Histogram(
"rpc.server.duration",
metric.WithDescription("Measures the duration of inbound RPC."),
metric.WithUnit("ms"),
semconv.RPCServerDurationName,
metric.WithDescription(semconv.RPCServerDurationDescription),
metric.WithUnit(semconv.RPCServerDurationUnit),
)
if err != nil {
otel.Handle(err)
Expand All @@ -75,9 +75,9 @@ func NewServerHandler(opts ...Option) stats.Handler {
}

h.inSize, err = meter.Int64Histogram(
"rpc.server.request.size",
metric.WithDescription("Measures size of RPC request messages (uncompressed)."),
metric.WithUnit("By"),
semconv.RPCServerRequestSizeName,
metric.WithDescription(semconv.RPCServerRequestSizeDescription),
metric.WithUnit(semconv.RPCServerRequestSizeUnit),
)
if err != nil {
otel.Handle(err)
Expand All @@ -87,9 +87,9 @@ func NewServerHandler(opts ...Option) stats.Handler {
}

h.outSize, err = meter.Int64Histogram(
"rpc.server.response.size",
metric.WithDescription("Measures size of RPC response messages (uncompressed)."),
metric.WithUnit("By"),
semconv.RPCServerResponseSizeName,
metric.WithDescription(semconv.RPCServerResponseSizeDescription),
metric.WithUnit(semconv.RPCServerResponseSizeUnit),
)
if err != nil {
otel.Handle(err)
Expand All @@ -99,9 +99,9 @@ func NewServerHandler(opts ...Option) stats.Handler {
}

h.inMsg, err = meter.Int64Histogram(
"rpc.server.requests_per_rpc",
metric.WithDescription("Measures the number of messages received per RPC. Should be 1 for all non-streaming RPCs."),
metric.WithUnit("{count}"),
semconv.RPCServerRequestsPerRPCName,
metric.WithDescription(semconv.RPCServerRequestsPerRPCDescription),
metric.WithUnit(semconv.RPCServerRequestsPerRPCUnit),
)
if err != nil {
otel.Handle(err)
Expand All @@ -111,9 +111,9 @@ func NewServerHandler(opts ...Option) stats.Handler {
}

h.outMsg, err = meter.Int64Histogram(
"rpc.server.responses_per_rpc",
metric.WithDescription("Measures the number of messages received per RPC. Should be 1 for all non-streaming RPCs."),
metric.WithUnit("{count}"),
semconv.RPCServerResponsesPerRPCName,
metric.WithDescription(semconv.RPCServerResponsesPerRPCDescription),
metric.WithUnit(semconv.RPCServerResponsesPerRPCUnit),
)
if err != nil {
otel.Handle(err)
Expand All @@ -139,7 +139,7 @@ func (h *serverHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) cont
ctx = extract(ctx, h.Propagators)

name, attrs := internal.ParseFullMethod(info.FullMethodName)
attrs = append(attrs, RPCSystemGRPC)
attrs = append(attrs, semconv.RPCSystemGRPC)

record := true
if h.Filter != nil {
Expand Down Expand Up @@ -198,9 +198,9 @@ func NewClientHandler(opts ...Option) stats.Handler {

var err error
h.duration, err = meter.Float64Histogram(
"rpc.client.duration",
metric.WithDescription("Measures the duration of inbound RPC."),
metric.WithUnit("ms"),
semconv.RPCClientDurationName,
metric.WithDescription(semconv.RPCClientDurationDescription),
metric.WithUnit(semconv.RPCClientDurationUnit),
)
if err != nil {
otel.Handle(err)
Expand All @@ -210,9 +210,9 @@ func NewClientHandler(opts ...Option) stats.Handler {
}

h.outSize, err = meter.Int64Histogram(
"rpc.client.request.size",
metric.WithDescription("Measures size of RPC request messages (uncompressed)."),
metric.WithUnit("By"),
semconv.RPCClientRequestSizeName,
metric.WithDescription(semconv.RPCClientRequestSizeDescription),
metric.WithUnit(semconv.RPCClientRequestSizeUnit),
)
if err != nil {
otel.Handle(err)
Expand All @@ -222,9 +222,9 @@ func NewClientHandler(opts ...Option) stats.Handler {
}

h.inSize, err = meter.Int64Histogram(
"rpc.client.response.size",
metric.WithDescription("Measures size of RPC response messages (uncompressed)."),
metric.WithUnit("By"),
semconv.RPCClientResponseSizeName,
metric.WithDescription(semconv.RPCClientResponseSizeDescription),
metric.WithUnit(semconv.RPCClientResponseSizeUnit),
)
if err != nil {
otel.Handle(err)
Expand All @@ -234,9 +234,9 @@ func NewClientHandler(opts ...Option) stats.Handler {
}

h.outMsg, err = meter.Int64Histogram(
"rpc.client.requests_per_rpc",
metric.WithDescription("Measures the number of messages received per RPC. Should be 1 for all non-streaming RPCs."),
metric.WithUnit("{count}"),
semconv.RPCClientRequestsPerRPCName,
metric.WithDescription(semconv.RPCClientRequestsPerRPCDescription),
metric.WithUnit(semconv.RPCClientRequestsPerRPCUnit),
)
if err != nil {
otel.Handle(err)
Expand All @@ -246,9 +246,9 @@ func NewClientHandler(opts ...Option) stats.Handler {
}

h.inMsg, err = meter.Int64Histogram(
"rpc.client.responses_per_rpc",
metric.WithDescription("Measures the number of messages received per RPC. Should be 1 for all non-streaming RPCs."),
metric.WithUnit("{count}"),
semconv.RPCClientResponsesPerRPCName,
metric.WithDescription(semconv.RPCClientResponsesPerRPCDescription),
metric.WithUnit(semconv.RPCClientResponsesPerRPCUnit),
)
if err != nil {
otel.Handle(err)
Expand All @@ -263,7 +263,7 @@ func NewClientHandler(opts ...Option) stats.Handler {
// TagRPC can attach some information to the given context.
func (h *clientHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context {
name, attrs := internal.ParseFullMethod(info.FullMethodName)
attrs = append(attrs, RPCSystemGRPC)
attrs = append(attrs, semconv.RPCSystemGRPC)

record := true
if h.Filter != nil {
Expand Down Expand Up @@ -333,10 +333,10 @@ func (c *config) handleRPC(
if c.ReceivedEvent && span.IsRecording() {
span.AddEvent("message",
trace.WithAttributes(
semconv.MessageTypeReceived,
semconv.MessageIDKey.Int64(messageId),
semconv.MessageCompressedSizeKey.Int(rs.CompressedLength),
semconv.MessageUncompressedSizeKey.Int(rs.Length),
semconv.RPCMessageTypeReceived,
semconv.RPCMessageIDKey.Int64(messageId),
semconv.RPCMessageCompressedSizeKey.Int(rs.CompressedLength),
semconv.RPCMessageUncompressedSizeKey.Int(rs.Length),
),
)
}
Expand All @@ -349,18 +349,18 @@ func (c *config) handleRPC(
if c.SentEvent && span.IsRecording() {
span.AddEvent("message",
trace.WithAttributes(
semconv.MessageTypeSent,
semconv.MessageIDKey.Int64(messageId),
semconv.MessageCompressedSizeKey.Int(rs.CompressedLength),
semconv.MessageUncompressedSizeKey.Int(rs.Length),
semconv.RPCMessageTypeSent,
semconv.RPCMessageIDKey.Int64(messageId),
semconv.RPCMessageCompressedSizeKey.Int(rs.CompressedLength),
semconv.RPCMessageUncompressedSizeKey.Int(rs.Length),
),
)
}
case *stats.OutTrailer:
case *stats.OutHeader:
if span.IsRecording() {
if p, ok := peer.FromContext(ctx); ok {
span.SetAttributes(peerAttr(p.Addr.String())...)
span.SetAttributes(serverAddrAttrs(p.Addr.String())...)
}
}
case *stats.End:
Expand Down
Loading
Loading