-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datadog): add dd tracing decorator
- Loading branch information
1 parent
2b7ccb3
commit 3101db1
Showing
4 changed files
with
118 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package datadog | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
const ( | ||
TraceIDKey = "dd.trace_id" | ||
SpanIDKey = "dd.span_id" | ||
) | ||
|
||
func TraceIDFromHexFormat(id string) string { | ||
return convertHexIDToUint(id) | ||
} | ||
|
||
func SpanIDFromHexFormat(id string) string { | ||
return convertHexIDToUint(id) | ||
} | ||
|
||
func convertHexIDToUint(id string) string { | ||
if len(id) < 16 { | ||
return "" | ||
} | ||
if len(id) > 16 { | ||
id = id[16:] | ||
} | ||
intValue, err := strconv.ParseUint(id, 16, 64) | ||
if err != nil { | ||
return "" | ||
} | ||
return strconv.FormatUint(intValue, 10) | ||
} |
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 datadog | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestTraceIDFromHexFormat(t *testing.T) { | ||
traceID := "0ef42e66522e5a9183241106963acf99" | ||
expectedTraceID := "9449696638118055833" | ||
|
||
result := TraceIDFromHexFormat(traceID) | ||
|
||
if result != expectedTraceID { | ||
t.Errorf("expected result trace id to be %q got %q", expectedTraceID, result) | ||
} | ||
} | ||
|
||
func TestSpanIDFromHexFormat(t *testing.T) { | ||
spanID := "0102040810203040" | ||
expectedSpanID := "72624976668143680" | ||
|
||
result := SpanIDFromHexFormat(spanID) | ||
|
||
if result != expectedSpanID { | ||
t.Errorf("expected result span id to be %q got %q", expectedSpanID, result) | ||
} | ||
} |
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