-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
internal: implement new tag for trace source #3230
Merged
+385
−20
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1e1d235
change tracingAsTransport environment variable
genesor e138956
add helper type to set trace-source tag
genesor 630c868
use _dd.p.ts in Inject and Extract
genesor 674ce07
Merge remote-tracking branch 'origin/main' into ben.db/APPSEC-56328-a…
genesor 3f77000
add copyright headers to new files
genesor b184d80
Enable APPSEC_STANDALONE_V2 system test
genesor 7ab6733
Merge remote-tracking branch 'origin/main' into ben.db/APPSEC-56328-a…
genesor 18f9fef
Merge branch 'main' into ben.db/APPSEC-56328-asm-standalone-billing-v2
genesor 176883a
Merge branch 'main' into ben.db/APPSEC-56328-asm-standalone-billing-v2
genesor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,73 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2025 Datadog, Inc. | ||
|
||
package internal | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"gopkg.in/DataDog/dd-trace-go.v1/internal/log" | ||
) | ||
|
||
// TraceSource represents the 8-bit bitmask for the _dd.p.ts tag | ||
type TraceSource uint8 | ||
|
||
const ( | ||
APMTraceSource TraceSource = 0x01 | ||
ASMTraceSource TraceSource = 0x02 | ||
DSMTraceSource TraceSource = 0x04 | ||
DJMTraceSource TraceSource = 0x08 | ||
DBMTraceSource TraceSource = 0x10 | ||
) | ||
|
||
// String converts the bitmask to a two-character hexadecimal string | ||
func (ts TraceSource) String() string { | ||
return fmt.Sprintf("%02X", uint8(ts)) | ||
} | ||
|
||
// ParseTraceSource parses a hexadecimal string into a TraceSource bitmask | ||
func ParseTraceSource(hexStr string) (TraceSource, error) { | ||
// Ensure at least 2 chars, allowing up to 8 for forward compatibility (32-bit) | ||
if len(hexStr) < 2 || len(hexStr) > 8 { | ||
return 0, fmt.Errorf("invalid length for TraceSource mask, expected 2 to 8 characters") | ||
} | ||
|
||
// Parse the full mask as a 32-bit unsigned integer | ||
value, err := strconv.ParseUint(hexStr, 16, 32) | ||
if err != nil { | ||
return 0, fmt.Errorf("invalid hexadecimal format: %w", err) | ||
} | ||
|
||
// Extract only the least significant 8 bits (ensuring compliance with 8-bit mask) | ||
return TraceSource(value & 0xFF), nil | ||
} | ||
|
||
func VerifyTraceSourceEnabled(hexStr string, target TraceSource) bool { | ||
ts, err := ParseTraceSource(hexStr) | ||
if err != nil { | ||
if len(hexStr) != 0 { // Empty trace source should not trigger an error log. | ||
log.Error("invalid trace-source hex string given for source verification: %v", err) | ||
} | ||
return false | ||
} | ||
|
||
return ts.IsSet(target) | ||
} | ||
|
||
// Set enables specific TraceSource (bit) in the bitmask | ||
func (ts *TraceSource) Set(src TraceSource) { | ||
*ts |= src | ||
} | ||
|
||
// Unset disables specific TraceSource (bit) in the bitmask | ||
func (ts *TraceSource) Unset(src TraceSource) { | ||
*ts &^= src | ||
} | ||
|
||
// IsSet checks if a specific TraceSource (bit) is enabled | ||
func (ts TraceSource) IsSet(src TraceSource) bool { | ||
return ts&src != 0 | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi DataDog/system-tests#4216