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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The next release will require at least [Go 1.23].
### Changed

- Add custom attribute to the span after execution of the SDK rather than before in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#6543)
- Support for the `OTEL_HTTP_CLIENT_COMPATIBILITY_MODE=http/dup` environment variable in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin` to emit attributes for both the v1.20.0 and v1.26.0 semantic conventions. (#6778)

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import (

"github.com/gin-gonic/gin"

internalsemconv "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv"
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconvutil"
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.20.0"
oteltrace "go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -46,15 +44,17 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc {
if cfg.Propagators == nil {
cfg.Propagators = otel.GetTextMapPropagator()
}

if cfg.MeterProvider == nil {
cfg.MeterProvider = otel.GetMeterProvider()
}
meter := cfg.MeterProvider.Meter(
ScopeName,
metric.WithInstrumentationVersion(Version()),
)
sc := internalsemconv.NewHTTPServer(meter)

sc := semconv.NewHTTPServer(meter)
var hs semconv.HTTPServer

return func(c *gin.Context) {
requestStartTime := time.Now()

Expand All @@ -81,8 +81,8 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc {
}()
ctx := cfg.Propagators.Extract(savedCtx, propagation.HeaderCarrier(c.Request.Header))
opts := []oteltrace.SpanStartOption{
oteltrace.WithAttributes(semconvutil.HTTPServerRequest(service, c.Request)...),
oteltrace.WithAttributes(semconv.HTTPRoute(c.FullPath())),
oteltrace.WithAttributes(hs.RequestTraceAttrs(service, c.Request)...),
oteltrace.WithAttributes(hs.Route(c.FullPath())),
oteltrace.WithSpanKind(oteltrace.SpanKindServer),
}
var spanName string
Expand All @@ -104,7 +104,7 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc {
c.Next()

status := c.Writer.Status()
span.SetStatus(semconvutil.HTTPServerStatus(status))
span.SetStatus(hs.Status(status))
if status > 0 {
span.SetAttributes(semconv.HTTPStatusCode(status))
}
Expand All @@ -121,15 +121,15 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc {
additionalAttributes = cfg.MetricAttributeFn(c.Request)
}

sc.RecordMetrics(ctx, internalsemconv.ServerMetricData{
sc.RecordMetrics(ctx, semconv.ServerMetricData{
ServerName: service,
ResponseSize: int64(c.Writer.Size()),
MetricAttributes: internalsemconv.MetricAttributes{
MetricAttributes: semconv.MetricAttributes{
Req: c.Request,
StatusCode: status,
AdditionalAttributes: additionalAttributes,
},
MetricData: internalsemconv.MetricData{
MetricData: semconv.MetricData{
RequestSize: c.Request.ContentLength,
ElapsedTime: float64(time.Since(requestStartTime)) / float64(time.Millisecond),
},
Expand Down