Skip to content

Commit

Permalink
rename functions as per PR review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski committed Dec 2, 2023
1 parent 718555e commit 92ab475
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http
### Added

- Add `WithResourceAttributes` `InstrumentationOption` to configure `Instrumentation` to add additional resource attributes. ([#522](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/522))
- Add HTTP client instrumentation for `Transport.RoundTrip`. ([#529](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/529))
- Add HTTP client instrumentation for `Transport.roundTrip`. ([#529](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/529))

### Changed

Expand Down
24 changes: 12 additions & 12 deletions internal/pkg/instrumentation/bpf/net/http/client/bpf/probe.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ static __always_inline long inject_header(void* headers_ptr, struct span_context
}

// This instrumentation attaches uprobe to the following function:
// func net/http/client.Do(req *Request) (*Response, error)
SEC("uprobe/HttpClient_Do")
int uprobe_HttpClient_Do(struct pt_regs *ctx) {
// func net/http/transport.roundTrip(req *Request) (*Response, error)
SEC("uprobe/Transport_roundTrip")
int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
u64 request_pos = 2;
void *req_ptr = get_argument(ctx, request_pos);

Expand All @@ -172,15 +172,15 @@ int uprobe_HttpClient_Do(struct pt_regs *ctx) {
void *httpReq_ptr = bpf_map_lookup_elem(&http_events, &key);
if (httpReq_ptr != NULL)
{
bpf_printk("uprobe/HttpClient_Do already tracked with the current context");
bpf_printk("uprobe/Transport_RoundTrip already tracked with the current context");
return 0;
}

u32 map_id = 0;
struct http_request_t *httpReq = bpf_map_lookup_elem(&http_client_uprobe_storage_map, &map_id);
if (httpReq == NULL)
{
bpf_printk("uprobe/HttpClient_Do: httpReq is NULL");
bpf_printk("uprobe/Transport_roundTrip: httpReq is NULL");
return 0;
}

Expand All @@ -197,15 +197,15 @@ int uprobe_HttpClient_Do(struct pt_regs *ctx) {
}

if (!get_go_string_from_user_ptr((void *)(req_ptr+method_ptr_pos), httpReq->method, sizeof(httpReq->method))) {
bpf_printk("uprobe_HttpClient_Do: Failed to get method from request");
bpf_printk("uprobe_Transport_roundTrip: Failed to get method from request");
return 0;
}

// get path from Request.URL
void *url_ptr = 0;
bpf_probe_read(&url_ptr, sizeof(url_ptr), (void *)(req_ptr+url_ptr_pos));
if (!get_go_string_from_user_ptr((void *)(url_ptr+path_ptr_pos), httpReq->path, sizeof(httpReq->path))) {
bpf_printk("uprobe_HttpClient_Do: Failed to get path from Request.URL");
bpf_printk("uprobe_Transport_roundTrip: Failed to get path from Request.URL");
return 0;
}

Expand All @@ -214,7 +214,7 @@ int uprobe_HttpClient_Do(struct pt_regs *ctx) {
bpf_probe_read(&headers_ptr, sizeof(headers_ptr), (void *)(req_ptr+headers_ptr_pos));
long res = inject_header(headers_ptr, &httpReq->sc);
if (res < 0) {
bpf_printk("uprobe_HttpClient_Do: Failed to inject header");
bpf_printk("uprobe_Transport_roundTrip: Failed to inject header");
}

// Write event
Expand All @@ -224,16 +224,16 @@ int uprobe_HttpClient_Do(struct pt_regs *ctx) {
}

// This instrumentation attaches uretprobe to the following function:
// func net/http/client.Do(req *Request) (*Response, error)
SEC("uprobe/HttpClient_Do")
int uprobe_HttpClient_Do_Returns(struct pt_regs *ctx) {
// func net/http/transport.roundTrip(req *Request) (*Response, error)
SEC("uprobe/Transport_roundTrip")
int uprobe_Transport_roundTrip_Returns(struct pt_regs *ctx) {
u64 end_time = bpf_ktime_get_ns();
void *req_ctx_ptr = get_Go_context(ctx, 2, ctx_ptr_pos, false);
void *key = get_consistent_key(ctx, req_ctx_ptr);

struct http_request_t *http_req_span = bpf_map_lookup_elem(&http_events, &key);
if (http_req_span == NULL) {
bpf_printk("probe_HttpClient_Do_Returns: entry_state is NULL");
bpf_printk("probe_Transport_roundTrip_Returns: entry_state is NULL");
return 0;
}
bpf_map_delete_elem(&http_events, &key);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/pkg/instrumentation/bpf/net/http/client/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func New(logger logr.Logger) probe.Probe {
},
},
Uprobes: map[string]probe.UprobeFunc[bpfObjects]{
"net/http.(*Transport).roundTrip": uprobeDo,
"net/http.(*Transport).roundTrip": uprobeRoundTrip,
},

ReaderFn: func(obj bpfObjects) (*perf.Reader, error) {
Expand All @@ -90,14 +90,14 @@ func New(logger logr.Logger) probe.Probe {
}
}

func uprobeDo(name string, exec *link.Executable, target *process.TargetDetails, obj *bpfObjects) ([]link.Link, error) {
func uprobeRoundTrip(name string, exec *link.Executable, target *process.TargetDetails, obj *bpfObjects) ([]link.Link, error) {
offset, err := target.GetFunctionOffset(name)
if err != nil {
return nil, err
}

opts := &link.UprobeOptions{Address: offset}
l, err := exec.Uprobe("", obj.UprobeHttpClientDo, opts)
l, err := exec.Uprobe("", obj.UprobeTransportRoundTrip, opts)
if err != nil {
return nil, err
}
Expand All @@ -110,7 +110,7 @@ func uprobeDo(name string, exec *link.Executable, target *process.TargetDetails,

for _, ret := range retOffsets {
opts := &link.UprobeOptions{Address: ret}
l, err := exec.Uprobe("", obj.UprobeHttpClientDoReturns, opts)
l, err := exec.Uprobe("", obj.UprobeTransportRoundTripReturns, opts)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 92ab475

Please sign in to comment.