-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added OTEL support. Major refactoring (#9)
* added OTEL support. Major refactoring Signed-off-by: Frederic BIDON <fredbi@yahoo.com> * fixed unit test Signed-off-by: Frederic BIDON <fredbi@yahoo.com> --------- Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
- Loading branch information
Showing
50 changed files
with
1,389 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package itracer | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
var ( | ||
prefixLock sync.Mutex | ||
prefix = "function" | ||
) | ||
|
||
// RegisterPrefix sets a package level tracer prefix at initialization time. | ||
// | ||
// This is used as the key in structured logs to hold the signature of the trace. | ||
// | ||
// The default value is "function", so a log entry looks like: | ||
// | ||
// 2023-11-01T17:19:58.615+0100 INFO tracer/example_test.go:33 test { | ||
// "function": "tracer_test.ExampleStartSpan", | ||
// "field": "fred" | ||
// } | ||
func RegisterPrefix(custom string) { | ||
prefixLock.Lock() | ||
prefix = custom | ||
prefixLock.Unlock() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package itracer | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRegisterPrefix(t *testing.T) { | ||
const before = "function" | ||
t.Cleanup(func() { | ||
RegisterPrefix(before) | ||
}) | ||
|
||
// ... but still want to demonstrate that the registration is goroutine-safe | ||
require.NotPanics(t, func() { | ||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
RegisterPrefix("x") | ||
}() | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
RegisterPrefix("y") | ||
}() | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
RegisterPrefix("z") | ||
}() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package itracer | ||
|
||
import ( | ||
"path" | ||
"runtime" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
// SignedFields prepends a slice of zap.Fields with a signature string | ||
func SignedFields(signature string, fields []zap.Field) []zap.Field { | ||
signedFields := make([]zap.Field, 0, len(fields)+1) | ||
signedFields = append(signedFields, zap.String(prefix, signature)) | ||
signedFields = append(signedFields, fields...) | ||
|
||
return signedFields | ||
} | ||
|
||
// Signature returns the function name of the caller. | ||
func Signature() string { | ||
pc, _, _, ok := runtime.Caller(2) | ||
if ok { | ||
return path.Base(runtime.FuncForPC(pc).Name()) | ||
} | ||
|
||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
// Package log exposes logging utilities based on go.uber.org/zap. | ||
// | ||
// Opencensus tracing: | ||
// | ||
// Open Telemetry tracing: | ||
package log |
Oops, something went wrong.