Skip to content

Commit 0e82d09

Browse files
authored
Merge branch 'main' into codeboten/add-tls-support-grpc
2 parents 71aabb7 + eb2064c commit 0e82d09

File tree

11 files changed

+86
-20
lines changed

11 files changed

+86
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2929
- Fixed the value for configuring the OTLP exporter to use `grpc` instead of `grpc/protobuf` in `go.opentelemetry.io/contrib/config`. (#6338)
3030
- Allow marshaling types in `go.opentelemetry.io/contrib/config`. (#6347)
3131
- Removed the redundant handling of panic from the `HTML` function in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`. (#6373)
32+
- The `code.function` attribute emitted by `go.opentelemetry.io/contrib/bridges/otelslog` now stores just the function name instead the package path-qualified function name. The `code.namespace` attribute now stores the package path. (#6415)
3233

3334
<!-- Released section -->
3435
<!-- Don't change this section unless doing release -->

bridges/otelslog/handler.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
"log/slog"
5151
"runtime"
5252
"slices"
53+
"strings"
5354

5455
"go.opentelemetry.io/otel/log"
5556
"go.opentelemetry.io/otel/log/global"
@@ -192,9 +193,11 @@ func (h *Handler) convertRecord(r slog.Record) log.Record {
192193
if h.source {
193194
fs := runtime.CallersFrames([]uintptr{r.PC})
194195
f, _ := fs.Next()
196+
funcName, namespace := splitFuncName(f.Function)
195197
record.AddAttributes(
196198
log.String(string(semconv.CodeFilepathKey), f.File),
197-
log.String(string(semconv.CodeFunctionKey), f.Function),
199+
log.String(string(semconv.CodeFunctionKey), funcName),
200+
log.String(string(semconv.CodeNamespaceKey), namespace),
198201
log.Int(string(semconv.CodeLineNumberKey), f.Line),
199202
)
200203
}
@@ -476,3 +479,15 @@ func convert(v slog.Value) log.Value {
476479
return log.StringValue(fmt.Sprintf("unhandled: (%s) %+v", v.Kind(), v.Any()))
477480
}
478481
}
482+
483+
// splitFuncName splits package path-qualified function name into
484+
// function name and package full name (namespace). E.g. it splits
485+
// "github.com/my/repo/pkg.foo" into
486+
// "foo" and "github.com/my/repo/pkg".
487+
func splitFuncName(f string) (string, string) {
488+
i := strings.LastIndexByte(f, '.')
489+
if i < 0 {
490+
return "", ""
491+
}
492+
return f[i+1:], f[:i]
493+
}

bridges/otelslog/handler_test.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (h *wrapper) Handle(ctx context.Context, r slog.Record) error {
230230
func TestSLogHandler(t *testing.T) {
231231
// Capture the PC of this line
232232
pc, file, line, _ := runtime.Caller(0)
233-
funcName := runtime.FuncForPC(pc).Name()
233+
funcName, namespace := splitFuncName(runtime.FuncForPC(pc).Name())
234234

235235
cases := []testCase{
236236
{
@@ -414,6 +414,7 @@ func TestSLogHandler(t *testing.T) {
414414
checks: [][]check{{
415415
hasAttr(string(semconv.CodeFilepathKey), file),
416416
hasAttr(string(semconv.CodeFunctionKey), funcName),
417+
hasAttr(string(semconv.CodeNamespaceKey), namespace),
417418
hasAttr(string(semconv.CodeLineNumberKey), int64(line)),
418419
}},
419420
options: []Option{WithSource(true)},
@@ -510,6 +511,42 @@ func TestHandlerEnabled(t *testing.T) {
510511
assert.True(t, h.Enabled(ctx, slog.LevelDebug), "context not passed")
511512
}
512513

514+
func TestSplitFuncName(t *testing.T) {
515+
testCases := []struct {
516+
fullFuncName string
517+
wantFuncName string
518+
wantNamespace string
519+
}{
520+
{
521+
fullFuncName: "github.com/my/repo/pkg.foo",
522+
wantFuncName: "foo",
523+
wantNamespace: "github.com/my/repo/pkg",
524+
},
525+
{
526+
fullFuncName: "net/http.Get",
527+
wantFuncName: "Get",
528+
wantNamespace: "net/http",
529+
},
530+
{
531+
fullFuncName: "invalid",
532+
wantFuncName: "",
533+
wantNamespace: "",
534+
},
535+
{
536+
fullFuncName: ".",
537+
wantFuncName: "",
538+
wantNamespace: "",
539+
},
540+
}
541+
for _, tc := range testCases {
542+
t.Run(tc.fullFuncName, func(t *testing.T) {
543+
gotFuncName, gotNamespace := splitFuncName(tc.fullFuncName)
544+
assert.Equal(t, tc.wantFuncName, gotFuncName)
545+
assert.Equal(t, tc.wantNamespace, gotNamespace)
546+
})
547+
}
548+
}
549+
513550
func BenchmarkHandler(b *testing.B) {
514551
var (
515552
h slog.Handler
@@ -639,5 +676,18 @@ func BenchmarkHandler(b *testing.B) {
639676
})
640677
})
641678

679+
b.Run("(WithSource).Handle", func(b *testing.B) {
680+
handlers := make([]*Handler, b.N)
681+
for i := range handlers {
682+
handlers[i] = NewHandler("", WithSource(true))
683+
}
684+
685+
b.ReportAllocs()
686+
b.ResetTimer()
687+
for n := 0; n < b.N; n++ {
688+
err = handlers[n].Handle(ctx, record)
689+
}
690+
})
691+
642692
_, _ = h, err
643693
}

detectors/aws/eks/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ require (
66
github.com/stretchr/testify v1.10.0
77
go.opentelemetry.io/otel v1.32.0
88
go.opentelemetry.io/otel/sdk v1.32.0
9-
k8s.io/apimachinery v0.31.3
10-
k8s.io/client-go v0.31.3
9+
k8s.io/apimachinery v0.31.4
10+
k8s.io/client-go v0.31.4
1111
)
1212

1313
require (
@@ -45,7 +45,7 @@ require (
4545
google.golang.org/protobuf v1.35.2 // indirect
4646
gopkg.in/inf.v0 v0.9.1 // indirect
4747
gopkg.in/yaml.v3 v3.0.1 // indirect
48-
k8s.io/api v0.31.3 // indirect
48+
k8s.io/api v0.31.4 // indirect
4949
k8s.io/klog/v2 v2.130.1 // indirect
5050
k8s.io/kube-openapi v0.0.0-20241127205056-99599406b04f // indirect
5151
k8s.io/utils v0.0.0-20241210054802-24370beab758 // indirect

detectors/aws/eks/go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
131131
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
132132
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
133133
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
134-
k8s.io/api v0.31.3 h1:umzm5o8lFbdN/hIXbrK9oRpOproJO62CV1zqxXrLgk8=
135-
k8s.io/api v0.31.3/go.mod h1:UJrkIp9pnMOI9K2nlL6vwpxRzzEX5sWgn8kGQe92kCE=
136-
k8s.io/apimachinery v0.31.3 h1:6l0WhcYgasZ/wk9ktLq5vLaoXJJr5ts6lkaQzgeYPq4=
137-
k8s.io/apimachinery v0.31.3/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
138-
k8s.io/client-go v0.31.3 h1:CAlZuM+PH2cm+86LOBemaJI/lQ5linJ6UFxKX/SoG+4=
139-
k8s.io/client-go v0.31.3/go.mod h1:2CgjPUTpv3fE5dNygAr2NcM8nhHzXvxB8KL5gYc3kJs=
134+
k8s.io/api v0.31.4 h1:I2QNzitPVsPeLQvexMEsj945QumYraqv9m74isPDKhM=
135+
k8s.io/api v0.31.4/go.mod h1:d+7vgXLvmcdT1BCo79VEgJxHHryww3V5np2OYTr6jdw=
136+
k8s.io/apimachinery v0.31.4 h1:8xjE2C4CzhYVm9DGf60yohpNUh5AEBnPxCryPBECmlM=
137+
k8s.io/apimachinery v0.31.4/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
138+
k8s.io/client-go v0.31.4 h1:t4QEXt4jgHIkKKlx06+W3+1JOwAFU/2OPiOo7H92eRQ=
139+
k8s.io/client-go v0.31.4/go.mod h1:kvuMro4sFYIa8sulL5Gi5GFqUPvfH2O/dXuKstbaaeg=
140140
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
141141
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
142142
k8s.io/kube-openapi v0.0.0-20241127205056-99599406b04f h1:nLHvOvs1CZ+FAEwR4EqLeRLfbtWQNlIu5g393Hq/1UM=

instrumentation/github.com/labstack/echo/otelecho/example/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ replace (
88
)
99

1010
require (
11-
github.com/labstack/echo/v4 v4.13.0
11+
github.com/labstack/echo/v4 v4.13.1
1212
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.57.0
1313
go.opentelemetry.io/otel v1.32.0
1414
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.32.0

instrumentation/github.com/labstack/echo/otelecho/example/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
99
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1010
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1111
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
12-
github.com/labstack/echo/v4 v4.13.0 h1:8DjSi4H/k+RqoOmwXkxW14A2H1pdPdS95+qmdJ4q1Tg=
13-
github.com/labstack/echo/v4 v4.13.0/go.mod h1:61j7WN2+bp8V21qerqRs4yVlVTGyOagMBpF0vE7VcmM=
12+
github.com/labstack/echo/v4 v4.13.1 h1:q3+CpQlYhJwpRr9+08pX0IdlabTIpnIhrg2AKPSKhFE=
13+
github.com/labstack/echo/v4 v4.13.1/go.mod h1:61j7WN2+bp8V21qerqRs4yVlVTGyOagMBpF0vE7VcmM=
1414
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
1515
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
1616
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=

instrumentation/github.com/labstack/echo/otelecho/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22
55
replace go.opentelemetry.io/contrib/propagators/b3 => ../../../../../propagators/b3
66

77
require (
8-
github.com/labstack/echo/v4 v4.13.0
8+
github.com/labstack/echo/v4 v4.13.1
99
github.com/stretchr/testify v1.10.0
1010
go.opentelemetry.io/contrib/propagators/b3 v1.32.0
1111
go.opentelemetry.io/otel v1.32.0

instrumentation/github.com/labstack/echo/otelecho/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
77
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
88
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
99
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
10-
github.com/labstack/echo/v4 v4.13.0 h1:8DjSi4H/k+RqoOmwXkxW14A2H1pdPdS95+qmdJ4q1Tg=
11-
github.com/labstack/echo/v4 v4.13.0/go.mod h1:61j7WN2+bp8V21qerqRs4yVlVTGyOagMBpF0vE7VcmM=
10+
github.com/labstack/echo/v4 v4.13.1 h1:q3+CpQlYhJwpRr9+08pX0IdlabTIpnIhrg2AKPSKhFE=
11+
github.com/labstack/echo/v4 v4.13.1/go.mod h1:61j7WN2+bp8V21qerqRs4yVlVTGyOagMBpF0vE7VcmM=
1212
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
1313
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
1414
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=

instrumentation/github.com/labstack/echo/otelecho/test/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otel
44
go 1.22
55

66
require (
7-
github.com/labstack/echo/v4 v4.13.0
7+
github.com/labstack/echo/v4 v4.13.1
88
github.com/stretchr/testify v1.10.0
99
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.57.0
1010
go.opentelemetry.io/otel v1.32.0

0 commit comments

Comments
 (0)