-
Notifications
You must be signed in to change notification settings - Fork 117
Manual instrumentation support - Phase 1 #523
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
Merged
MrAlias
merged 37 commits into
open-telemetry:main
from
RonFed:manual_instrumentation_support
Dec 7, 2023
+1,337
−10
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
959be3c
Initial instrumentation of otel sdk trace functions
RonFed cad101c
Add offsets for otel go sdk
RonFed dbad5eb
Pass the user defined span name through eBPF
RonFed 9c2c331
Initial attribute parsing
RonFed f989d66
Fix struct for attribute value
RonFed 9119c73
Try more efficient attribute encoding, currently only working for num…
RonFed 6ba47b8
Initial draft
RonFed ae3590f
Merge branch 'main' into manual_instrumentation_support
RonFed 390a4b7
Instrument Otel API functions to integrate manual spans with automati…
RonFed 6302d75
revert changes to verifier log collection settings
RonFed 7898724
Add tests for otel API instrumentation
RonFed 53a0daa
update changelog and lint
RonFed 6d1b33d
Check kernel version
RonFed 6d8cdfd
Change format of attributes in eBPF to make the verification easier
RonFed e5fbc27
Merge branch 'main' into manual_instrumentation_support
RonFed ac6d4ab
Small fix
RonFed 9ff76c1
Adding printk if attribute is too long for buffer
RonFed ea1f315
Update internal/include/otel_types.h
RonFed bb5657a
Code review 1
RonFed 267e931
Apply suggestions from code review
RonFed c5c7319
rename WithOtelApi to globalImpl
RonFed 2051021
Rename probe folder
RonFed 6e838b4
Inject attribute types consts from Go
RonFed fdea0b0
add cli flag for otel-global to record telemetry from the OpenTelemet…
RonFed a5a6964
debug tests
RonFed abff818
fix debug
RonFed f5a2627
modify set_attr_value
RonFed 3dd9447
print verifier log
RonFed 18dd13c
larger verifier log
RonFed 9c83561
...
RonFed f4690cf
simplify eBPF code
RonFed 12feb58
Clean-up and updating changelog
RonFed fcd527c
run make precommit
RonFed 42b3691
Fix doc
RonFed 2937ffb
Merge branch 'main' into manual_instrumentation_support
RonFed 6205df5
Apply suggestions from code review
MrAlias 5902fd4
Merge branch 'main' into manual_instrumentation_support
MrAlias 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,143 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef _OTEL_TYPES_H | ||
#define _OTEL_TYPES_H | ||
|
||
#include "go_types.h" | ||
#include "common.h" | ||
|
||
// Injected in init | ||
volatile const u64 attr_type_invalid; | ||
|
||
volatile const u64 attr_type_bool; | ||
volatile const u64 attr_type_int64; | ||
volatile const u64 attr_type_float64; | ||
volatile const u64 attr_type_string; | ||
|
||
volatile const u64 attr_type_boolslice; | ||
volatile const u64 attr_type_int64slice; | ||
volatile const u64 attr_type_float64slice; | ||
volatile const u64 attr_type_stringslice; | ||
|
||
/* Defintions should mimic structs defined in go.opentelemetry.io/otel/attribute */ | ||
|
||
typedef struct go_otel_attr_value { | ||
u64 vtype; | ||
u64 numeric; | ||
struct go_string string; | ||
struct go_iface slice; | ||
} go_otel_attr_value_t; | ||
|
||
typedef struct go_otel_key_value { | ||
struct go_string key; | ||
go_otel_attr_value_t value; | ||
} go_otel_key_value_t; | ||
|
||
#define OTEL_ATTRIBUTE_KEY_MAX_LEN (32) | ||
#define OTEL_ATTRIBUTE_VALUE_MAX_LEN (128) | ||
#define OTEL_ATTRUBUTE_MAX_COUNT (16) | ||
RonFed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
typedef struct otel_attirbute { | ||
u16 val_length; | ||
u8 vtype; | ||
u8 reserved; | ||
char key[OTEL_ATTRIBUTE_KEY_MAX_LEN]; | ||
char value[OTEL_ATTRIBUTE_VALUE_MAX_LEN]; | ||
} otel_attirbute_t; | ||
|
||
typedef struct otel_attributes { | ||
otel_attirbute_t attrs[OTEL_ATTRUBUTE_MAX_COUNT]; | ||
u8 valid_attrs; | ||
}__attribute__((packed)) otel_attributes_t; | ||
|
||
static __always_inline bool set_attr_value(otel_attirbute_t *attr, go_otel_attr_value_t *go_attr_value) | ||
{ | ||
u64 vtype = go_attr_value->vtype; | ||
|
||
if (vtype == attr_type_invalid) { | ||
bpf_printk("Invalid attribute value type\n"); | ||
return false; | ||
} | ||
|
||
// Constant size values | ||
if (vtype == attr_type_bool || | ||
vtype == attr_type_int64 || | ||
vtype == attr_type_float64) { | ||
bpf_probe_read(attr->value, sizeof(s64), &go_attr_value->numeric); | ||
return true; | ||
} | ||
|
||
// String values | ||
if (vtype == attr_type_string) { | ||
if (go_attr_value->string.len >= OTEL_ATTRIBUTE_VALUE_MAX_LEN) { | ||
bpf_printk("Aattribute string value is too long\n"); | ||
return false; | ||
RonFed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return get_go_string_from_user_ptr(&go_attr_value->string, attr->value, OTEL_ATTRIBUTE_VALUE_MAX_LEN); | ||
} | ||
|
||
// TODO (#525): handle slices | ||
return false; | ||
} | ||
|
||
static __always_inline void convert_go_otel_attributes(void *attrs_buf, s64 slice_len, otel_attributes_t *enc_attrs) | ||
{ | ||
if (attrs_buf == NULL || enc_attrs == NULL){ | ||
return; | ||
} | ||
|
||
if (slice_len < 1) { | ||
return; | ||
} | ||
|
||
s64 num_attrs = slice_len < OTEL_ATTRUBUTE_MAX_COUNT ? slice_len : OTEL_ATTRUBUTE_MAX_COUNT; | ||
go_otel_key_value_t *go_attr = (go_otel_key_value_t*)attrs_buf; | ||
go_otel_attr_value_t go_attr_value = {0}; | ||
struct go_string go_str = {0}; | ||
u8 valid_attrs = 0; | ||
|
||
for (u32 go_attr_index = 0; go_attr_index < num_attrs; go_attr_index++) { | ||
__builtin_memset(&go_attr_value, 0, sizeof(go_otel_attr_value_t)); | ||
// Read the value struct | ||
bpf_probe_read(&go_attr_value, sizeof(go_otel_attr_value_t), &go_attr[go_attr_index].value); | ||
|
||
if (go_attr_value.vtype == attr_type_invalid) { | ||
continue; | ||
} | ||
|
||
// Read the key string | ||
bpf_probe_read(&go_str, sizeof(struct go_string), &go_attr[go_attr_index].key); | ||
if (go_str.len >= OTEL_ATTRIBUTE_KEY_MAX_LEN) { | ||
// key string is too large | ||
bpf_printk("Attribute key string is too long\n"); | ||
continue; | ||
} | ||
|
||
if (!get_go_string_from_user_ptr(&go_str, enc_attrs->attrs[valid_attrs].key, OTEL_ATTRIBUTE_KEY_MAX_LEN)) { | ||
continue; | ||
} | ||
|
||
if (!set_attr_value(&enc_attrs->attrs[valid_attrs], &go_attr_value)) { | ||
continue; | ||
} | ||
|
||
enc_attrs->attrs[valid_attrs].vtype = go_attr_value.vtype; | ||
valid_attrs++; | ||
} | ||
|
||
enc_attrs->valid_attrs = valid_attrs; | ||
} | ||
|
||
#endif |
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.
Uh oh!
There was an error while loading. Please reload this page.