Skip to content

Conversation

@jbachorik
Copy link
Collaborator

@jbachorik jbachorik commented Aug 22, 2025

What does this PR do?:
It adds the support for publishing process context in OTel friendly way.

Additional Notes:
See https://github.com/DataDog/fullhost-code-hotspots-wip/pull/2

How to test the change?:

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.
  • JIRA: PROF-12377

Unsure? Have a question? Request a review!

Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Looks like it was very straightforward to wire this in, which was the point :)

Left a few notes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I can see why having a no-op fallback may be useful for implementers. I'll borrow steal build on this idea and add it on the reference implementation so we don't need to maintain it separately

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jbachorik and others added 4 commits August 26, 2025 11:41
- Add comprehensive gradle patching for otel_process_ctx.c to .cpp conversion
- Add Linux preprocessor guards and C++ explicit casts for compilation
- Fix gradle task dependencies and caching for proper file handling
- Implement proper publish/update API usage in JNI setProcessCtx0
- Add native read functionality through JNI wrapper
- Update ProcessContextTest for test resilience and native read testing
- Resolve all compilation failures in gtest tasks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jbachorik jbachorik requested a review from MattAlp August 26, 2025 15:21
Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM left a few small notes, but overall looks very reasonable!

@ivoanjo
Copy link
Member

ivoanjo commented Aug 29, 2025

I've opened #267 to bring the latest version of the reference library on top of this PR/branch :)

@jbachorik
Copy link
Collaborator Author

@zhengyu123 I addressed the locking. If you could re-review and potentially approve ...

@r1viollet
Copy link
Contributor

Exciting to see this! 👏

@jbachorik jbachorik dismissed zhengyu123’s stale review September 1, 2025 12:58

I addressed all concerns.

@jbachorik
Copy link
Collaborator Author

@r1viollet Can you 👍 this?
@zhengyu123 and @MattAlp are off today because of public holiday ...

@jbachorik jbachorik merged commit 887508d into main Sep 3, 2025
182 of 183 checks passed
@jbachorik jbachorik deleted the jb/ebf_ctx branch September 3, 2025 16:10
@github-actions github-actions bot added this to the 1.30.0 milestone Sep 3, 2025
// (due to the MADV_DONTFORK) and we don't need to do anything to it.
if (state.mapping != NULL && state.mapping != MAP_FAILED && getpid() == state.publisher_pid) {
long mapping_size = size_for_mapping();
if (mapping_size == -1 || munmap(published_state.mapping, mapping_size) == -1) return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confusion between state.mapping and published_state.mapping

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice spot! I'll open a PR to fix this.

data_out->telemetry_sdk_name = value;
} else {
// Unknown key, put it into resources
char *key = (char *) calloc(key_len + 1, 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid the manual allocs ? if we have to handle frees on error we will make mistakes
example not freeing other resources (data_out->resources )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the resources are being cleared in the caller:

    if (!otel_process_ctx_decode_payload(mapping->otel_process_payload, &data)) {
      otel_process_ctx_read_data_drop(data);

For avoiding manual allocs, any suggestions? Were you thinking something closer to -- allocate a big block of and then just memcpy into it?

(Also the reading support is mostly only for debugging/tests and can even be disabled individually, as it's not particularly interesting in actual production apps)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: when I initially wrote this I forgot that we had to be compatible with C 😄
In C++ the types would have defined the ownership.

In C, we can try to be more symmetrical on alloc / free code paths: having clear init / free functions to look for.
I'm not sure we need to polish this right now.

@r1viollet
Copy link
Contributor

More generally I think we need to consider invalid inputs, size limits, null values (as these can come from users). Java might be handling some of this. This is not a blocker for prototype.

@ivoanjo
Copy link
Member

ivoanjo commented Sep 4, 2025

More generally I think we need to consider invalid inputs, size limits, null values (as these can come from users). Java might be handling some of this. This is not a blocker for prototype.

I believe all of these are checked? validate_and_calculate_payload_size checks the size of every string + that it's not null while encoding; or do you mean in the reader?

This is not a blocker for prototype.

We definitely want to make this as production-quality as possible (especially the writer, but the reader as a bonus) so all feedback for that is welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants