Skip to content
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

OTTL int to hex conversion function #31929

Closed
krokwen opened this issue Mar 25, 2024 · 9 comments
Closed

OTTL int to hex conversion function #31929

krokwen opened this issue Mar 25, 2024 · 9 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers pkg/ottl priority:p2 Medium

Comments

@krokwen
Copy link

krokwen commented Mar 25, 2024

Component(s)

pkg/ottl

Is your feature request related to a problem? Please describe.

I'm unable to convert uint64 trace/span id to proper hex value during logs parsing

Describe the solution you'd like

Function name "Hex" that will accept two arguments:

  1. Int value
  2. total length in bytes

second parameter is required to prepend the string with zeros to get the hex string of fixed length (trace_id.string and span_id.string accept only 32 char hex string, i'e 16-bytes)

Example:

# attributes['dd_trace_id']="13498527101626869733"
processors:
  transform:
    error_mode: ignore
    log_statements:
      - context: log
        statements:
          - set(trace_id.string, Hex(Int(attributes["dd_trace_id"]), 16))
# trace_id.string now is "0000000000000000bb5466e17373e7e5"

Describe alternatives you've considered

  1. I tried to convert trace id to hex on the PHP-side
    It's not possible due to PHP is using signed int64, and in result a lot of trace ids become '7fffffffffffffff' when I trying to dechex((int) $ddTraceId)

  2. The newer DDTrace (0.94+ or 0.96+) provides a method to acquire hex trace id (without leading zeros), but the newer extension breaks up my whole app for no reason (broken read from .env file...)

Additional context

Our laravel-based project uses DDTrace PHP-extension (0.88.1) for tracing purposes.
I can get traces easily using receiver/datadogreceiver (it processes trace_id internally by it's own)
But when I trying to parse application logs I have an issue with parsing of the datadog trace id which comes as uint64 that I unable to convert to hex value and write it as trace_id.string.

@krokwen krokwen added enhancement New feature or request needs triage New item requiring triage labels Mar 25, 2024
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@TylerHelmuth
Copy link
Member

@krokwen what are you using to collect the datadog logs that have a trace_id that is an uint64?

@krokwen
Copy link
Author

krokwen commented Mar 25, 2024

It's not me, but our dev's =) and it's not a datadog logs, just regular app logs, json-serialized, including current trace and span IDs

It's done like this in our Logging\DatadogHandler

$context = \DDTrace\current_context();
$record->extra['dd'] = [
  'trace_id' => $context['trace_id'],
  'span_id' => $context['span_id'],
];

I tried to poke a stick into it, examined few methods like \DDTrace\root_span() or \DDTrace\active_span() and didn't found there any hex-like notation, only stringified long integers

@krokwen
Copy link
Author

krokwen commented Mar 25, 2024

->hexId() method is not available in my version of DDTrace, as I said before, the newer version breaks up the whole app...

@TylerHelmuth
Copy link
Member

The OTTL grammar supports Byte Slices, represented as hex strings such as 0x0001. A Converter like Hex would act similar to other Converters like String or Int where it takes a single input and attempts to convert it to the new type. So Hex(13498527101626869733) would return a byte slice represented by 0xBB5466E17373E7E5. Ultimately we'd want to be able to pass that value to https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/ottlfuncs/README.md#traceid

@crobert-1
Copy link
Member

Looks like from what Tyler suggested this is a valid enhancement request, removing needs triage. (Let me know if I misunderstood though.)

@odubajDT
Copy link
Contributor

odubajDT commented Jun 6, 2024

Hi, I would like to work on this issue cc @evan-bradley

evan-bradley pushed a commit that referenced this issue Jun 21, 2024
**Description:** <Describe what has changed.>
Adds ByteSliceLikeGetter interface due to future support of Hex()
converter

**Link to tracking Issue:** #31929 

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>

---------

Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
evan-bradley pushed a commit that referenced this issue Jul 3, 2024
**Description:** <Describe what has changed.>
Adds a Hex function to the OTTL package. This function can be applied to
following values:

- float64
- string
- bool
- int64
- []byte

The resulting value will be of type []byte.

**Link to tracking Issue:**
#31929

**Testing:**
- unit tests
- e2e tests

Depends on
#33536

---------

Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
@odubajDT
Copy link
Contributor

I think this issue can be closed @TylerHelmuth @evan-bradley

@evan-bradley
Copy link
Contributor

Closing as resolved via #33450.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers pkg/ottl priority:p2 Medium
Projects
None yet
Development

No branches or pull requests

5 participants