Skip to content

Allow loading multiple specs per tracer#1373

Merged
grcevski merged 5 commits into
open-telemetry:mainfrom
rafaelroquetto:multi_spec
Feb 27, 2026
Merged

Allow loading multiple specs per tracer#1373
grcevski merged 5 commits into
open-telemetry:mainfrom
rafaelroquetto:multi_spec

Conversation

@rafaelroquetto
Copy link
Copy Markdown
Contributor

@rafaelroquetto rafaelroquetto commented Feb 26, 2026

This effectively allows a tracer to be composed of multiple independent translation units - in other words, instead of doing:

// mytracer.c

#include "file1.c"
#include "file2.c"

A tracer can now go:generate individual .c files independently, each yielding its own .o file, treated as independent translation units. Map sharing continue to work as usual due to OBI_PIN_INTERNAL.

But why?

Glad you asked! Having different translation units allow us to have multiple/different definitions for a single function. For example, sock msg programs operate on a struct sk_msg context, whilst sock skb programs operate on struct __skb_buf contexts. These have similar semantics, e.g.:

  • you can pull data
  • they both provide direct packet access (data and data_end pointers)
  • likewise, they both have the concept of length/size

Being able to have multiple implementations allow writing common code. For instance:

//common_defs.h
// defines a common """interface"""
static __always_inline u32 ctx_len(void *ctx);
static __always_inline void ctx_pull_data(void *ctx, u32 len);
static __always_inline void *ctx_data(void *ctx);
static __always_inline void *ctx_data_end(void *ctx);

// sockmsg_defs.h
// sk_msg implementations

static __always_inline u32 ctx_len(void *ctx) {
    return ((struct sk_msg_md *)ctx)->size;
}

static __always_inline void ctx_pull_data(void *ctx, u32 len) {
    bpf_msg_pull_data(ctx, 0, len, 0);
}

static __always_inline void *ctx_data(void *ctx) {
    return ((struct sk_msg_md *)ctx)->data;
}

static __always_inline void *ctx_data_end(void *ctx) {
    return ((struct sk_msg_md *)ctx)->data_end;
}

// skb_defs.h
// skb implementations
static __always_inline u32 ctx_len(void *ctx) {
    return ((struct __sk_buff *)ctx)->len;
}

static __always_inline void ctx_pull_data(void *ctx, u32 len) {
    bpf_skb_pull_data(ctx, len);
}

static __always_inline void *ctx_data(void *ctx) {
    return ctx_skb_data((struct __sk_buff *)ctx);
}

static __always_inline void *ctx_data_end(void *ctx) {
    return ctx_skb_data_end((struct __sk_buff *)ctx);
}

// common logic code (context agnostic)
static __always_inline void init_http_request(void *ctx, struct socket_data *sk_data) {
    const u32 len = ctx_len(ctx);

    /* ... */
    const u32 nbytes = len > sizeof(info->buf) ? sizeof(info->buf) : len;

    ctx_pull_data(ctx, nbytes);

    const unsigned char *ptr = ctx_data(ctx);
    const unsigned char *e = ctx_data_end(ctx);

    /* ... */
}

The use case is exactly the one illustrated above: allowing programs featuring direct packet access to be generalised (WIP/different PR).

This PR changes tpinjector/sock_iter.c to be a separate translation unit as an example.

Checklist

@rafaelroquetto rafaelroquetto requested a review from a team as a code owner February 26, 2026 17:40
@rafaelroquetto rafaelroquetto marked this pull request as draft February 26, 2026 17:46
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 43.50649% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.77%. Comparing base (55f2804) to head (f506195).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
pkg/ebpf/tracer_linux.go 40.38% 26 Missing and 5 partials ⚠️
pkg/internal/ebpf/gpuevent/gpuevent.go 0.00% 13 Missing ⚠️
pkg/internal/ebpf/logenricher/logenricher.go 0.00% 13 Missing ⚠️
pkg/internal/ebpf/tpinjector/tpinjector.go 65.78% 11 Missing and 2 partials ⚠️
pkg/internal/ebpf/gotracer/gotracer.go 0.00% 12 Missing ⚠️
pkg/internal/ebpf/logger/logger.go 75.00% 2 Missing and 1 partial ⚠️
pkg/internal/ebpf/watcher/watcher.go 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1373      +/-   ##
==========================================
+ Coverage   43.75%   43.77%   +0.01%     
==========================================
  Files         310      310              
  Lines       33772    33816      +44     
==========================================
+ Hits        14777    14803      +26     
- Misses      18044    18058      +14     
- Partials      951      955       +4     
Flag Coverage Δ
integration-test 21.60% <32.06%> (+0.01%) ⬆️
integration-test-arm 0.00% <0.00%> (ø)
integration-test-vm-x86_64-5.15.152 0.00% <0.00%> (ø)
integration-test-vm-x86_64-6.10.6 0.00% <0.00%> (ø)
k8s-integration-test 2.31% <0.00%> (+<0.01%) ⬆️
oats-test 0.00% <0.00%> (ø)
unittests 44.63% <19.08%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rafaelroquetto rafaelroquetto marked this pull request as ready for review February 26, 2026 20:00
Copy link
Copy Markdown
Contributor

@mariomac mariomac left a comment

Choose a reason for hiding this comment

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

🪄

Copy link
Copy Markdown
Contributor

@mmat11 mmat11 left a comment

Choose a reason for hiding this comment

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

lgtm, nice!

Comment thread pkg/ebpf/tracer_linux.go
Comment thread pkg/internal/ebpf/gotracer/gotracer.go Outdated
Copy link
Copy Markdown
Contributor

@grcevski grcevski left a comment

Choose a reason for hiding this comment

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

LGTM! I left some minor comments.

Comment thread pkg/ebpf/tracer_linux.go Outdated
Comment thread pkg/internal/ebpf/tpinjector/tpinjector_test.go Outdated
Comment thread pkg/ebpf/tracer_linux.go
@grcevski grcevski merged commit ef0fe2e into open-telemetry:main Feb 27, 2026
65 checks passed
@rafaelroquetto rafaelroquetto deleted the multi_spec branch February 27, 2026 20:34
NimrodAvni78 pushed a commit to coralogix/opentelemetry-ebpf-instrumentation that referenced this pull request Mar 1, 2026
@MrAlias MrAlias added this to the v0.6.0 milestone Mar 2, 2026
@MrAlias MrAlias mentioned this pull request Mar 5, 2026
@pinoOgni pinoOgni mentioned this pull request Mar 17, 2026
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.

5 participants