Skip to content

Commit 9ff3dfa

Browse files
authored
http: add support for GraphQL attributes (#755)
* http: add support for GraphQL attributes Signed-off-by: Mattia Meleleo <[email protected]> * add integration test --------- Signed-off-by: Mattia Meleleo <[email protected]>
1 parent 885e4c3 commit 9ff3dfa

File tree

23 files changed

+763
-145
lines changed

23 files changed

+763
-145
lines changed

bpf/generictracer/k_tracer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,13 @@ int obi_handle_buf_with_args(void *ctx) {
11401140
}
11411141
}
11421142
}
1143+
1144+
http_send_large_buffer(info,
1145+
(void *)args->u_buf,
1146+
args->bytes_len,
1147+
args->packet_type,
1148+
args->direction,
1149+
k_large_buf_action_append);
11431150
} else if (still_responding(info)) {
11441151
info->end_monotime_ns = bpf_ktime_get_ns();
11451152
}

bpf/generictracer/protocol_http.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,12 @@ __obi_protocol_http(struct pt_regs *ctx, unsigned char *(*tp_loop_fn)(unsigned c
600600
return 0;
601601
}
602602
} else if ((args->packet_type == PACKET_TYPE_RESPONSE) && (info->status == 0)) {
603+
http_send_large_buffer(info,
604+
(void *)args->u_buf,
605+
args->bytes_len,
606+
args->packet_type,
607+
args->direction,
608+
k_large_buf_action_init);
603609
handle_http_response(
604610
args->small_buf, &args->pid_conn, info, args->bytes_len, args->direction, args->ssl);
605611
} else if (still_reading(info)) {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require (
2929
github.com/shirou/gopsutil/v3 v3.24.5
3030
github.com/stretchr/testify v1.11.1
3131
github.com/tklauser/go-sysconf v0.3.15
32+
github.com/vektah/gqlparser/v2 v2.5.30
3233
github.com/vishvananda/netlink v1.3.1
3334
github.com/vladimirvivien/gexe v0.5.0
3435
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2

go.sum

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/AlessandroPomponio/go-gibberish v0.0.0-20191004143433-a2d4156f0396 h1
44
github.com/AlessandroPomponio/go-gibberish v0.0.0-20191004143433-a2d4156f0396/go.mod h1:2VCDG9kHYQ5vfYUqeoB7foVlcvIvB7rp9LxTELLD1qU=
55
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.29.0 h1:UQUsRi8WTzhZntp5313l+CHIAT95ojUI2lpP/ExlZa4=
66
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.29.0/go.mod h1:Cz6ft6Dkn3Et6l2v2a9/RpN7epQ1GtDlO6lj8bEcOvw=
7+
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
8+
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
79
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
810
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
911
github.com/aws/aws-sdk-go-v2 v1.38.1 h1:j7sc33amE74Rz0M/PoCpsZQ6OunLqys/m5antM0J+Z8=
@@ -232,8 +234,6 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
232234
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
233235
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
234236
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
235-
github.com/prometheus/client_golang v1.23.0 h1:ust4zpdl9r4trLY/gSjlm07PuiBq2ynaXXlptpfy8Uc=
236-
github.com/prometheus/client_golang v1.23.0/go.mod h1:i/o0R9ByOnHX0McrTMTyhYvKE4haaf2mW08I+jGAjEE=
237237
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
238238
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
239239
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
@@ -246,6 +246,8 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t
246246
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
247247
github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA=
248248
github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
249+
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
250+
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
249251
github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI=
250252
github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk=
251253
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
@@ -269,18 +271,16 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
269271
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
270272
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
271273
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
272-
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
273-
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
274274
github.com/tklauser/go-sysconf v0.3.15 h1:VE89k0criAymJ/Os65CSn1IXaol+1wrsFHEB8Ol49K4=
275275
github.com/tklauser/go-sysconf v0.3.15/go.mod h1:Dmjwr6tYFIseJw7a3dRLJfsHAMXZ3nEnL/aZY+0IuI4=
276-
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
277-
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
278276
github.com/tklauser/numcpus v0.10.0 h1:18njr6LDBk1zuna922MgdjQuJFjrdppsZG60sHGfjso=
279277
github.com/tklauser/numcpus v0.10.0/go.mod h1:BiTKazU708GQTYF4mB+cmlpT2Is1gLk7XVuEeem8LsQ=
280278
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
281279
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
282280
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
283281
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
282+
github.com/vektah/gqlparser/v2 v2.5.30 h1:EqLwGAFLIzt1wpx1IPpY67DwUujF1OfzgEyDsLrN6kE=
283+
github.com/vektah/gqlparser/v2 v2.5.30/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo=
284284
github.com/vishvananda/netlink v1.3.1 h1:3AEMt62VKqz90r0tmNhog0r/PpWKmrEShJU0wJW6bV0=
285285
github.com/vishvananda/netlink v1.3.1/go.mod h1:ARtKouGSTGchR8aMwmkzC0qiNPrrWO5JS/XMVl45+b4=
286286
github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zdEY=
@@ -482,9 +482,7 @@ golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7w
482482
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
483483
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
484484
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
485-
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
486485
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
487-
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
488486
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
489487
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
490488
golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4=
@@ -513,14 +511,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7 h1:
513511
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7/go.mod h1:kXqgZtrWaf6qS3jZOCnCH7WYfrvFjkC51bM8fz3RsCA=
514512
google.golang.org/genproto/googleapis/rpc v0.0.0-20250804133106-a7a43d27e69b h1:zPKJod4w6F1+nRGDI9ubnXYhU9NSWoFAijkHkUXeTK8=
515513
google.golang.org/genproto/googleapis/rpc v0.0.0-20250804133106-a7a43d27e69b/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
516-
google.golang.org/grpc v1.75.0 h1:+TW+dqTd2Biwe6KKfhE5JpiYIBWq865PhKGSXiivqt4=
517-
google.golang.org/grpc v1.75.0/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
518514
google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI=
519515
google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
520-
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
521-
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
522-
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
523-
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
524516
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
525517
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
526518
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -534,18 +526,12 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
534526
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
535527
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
536528
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
537-
k8s.io/api v0.34.0 h1:L+JtP2wDbEYPUeNGbeSa/5GwFtIA662EmT2YSLOkAVE=
538-
k8s.io/api v0.34.0/go.mod h1:YzgkIzOOlhl9uwWCZNqpw6RJy9L2FK4dlJeayUoydug=
539529
k8s.io/api v0.34.1 h1:jC+153630BMdlFukegoEL8E/yT7aLyQkIVuwhmwDgJM=
540530
k8s.io/api v0.34.1/go.mod h1:SB80FxFtXn5/gwzCoN6QCtPD7Vbu5w2n1S0J5gFfTYk=
541531
k8s.io/apiextensions-apiserver v0.33.0 h1:d2qpYL7Mngbsc1taA4IjJPRJ9ilnsXIrndH+r9IimOs=
542532
k8s.io/apiextensions-apiserver v0.33.0/go.mod h1:VeJ8u9dEEN+tbETo+lFkwaaZPg6uFKLGj5vyNEwwSzc=
543-
k8s.io/apimachinery v0.34.0 h1:eR1WO5fo0HyoQZt1wdISpFDffnWOvFLOOeJ7MgIv4z0=
544-
k8s.io/apimachinery v0.34.0/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw=
545533
k8s.io/apimachinery v0.34.1 h1:dTlxFls/eikpJxmAC7MVE8oOeP1zryV7iRyIjB0gky4=
546534
k8s.io/apimachinery v0.34.1/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw=
547-
k8s.io/client-go v0.34.0 h1:YoWv5r7bsBfb0Hs2jh8SOvFbKzzxyNo0nSb0zC19KZo=
548-
k8s.io/client-go v0.34.0/go.mod h1:ozgMnEKXkRjeMvBZdV1AijMHLTh3pbACPvK7zFR+QQY=
549535
k8s.io/client-go v0.34.1 h1:ZUPJKgXsnKwVwmKKdPfw4tB58+7/Ik3CrjOEhsiZ7mY=
550536
k8s.io/client-go v0.34.1/go.mod h1:kA8v0FP+tk6sZA0yKLRG67LWjqufAoSHA2xVGKw9Of8=
551537
k8s.io/component-base v0.33.0 h1:Ot4PyJI+0JAD9covDhwLp9UNkUja209OzsJ4FzScBNk=

pkg/app/request/metric_attributes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ func DBSystemName(val string) attribute.KeyValue {
112112
return attribute.Key(attr.DBSystemName).String(val)
113113
}
114114

115+
func GraphqlOperationType(val string) attribute.KeyValue {
116+
// TODO: replace once it's available in semconv
117+
return attribute.Key(attr.GraphQLOperationType).String(val)
118+
}
119+
115120
func ErrorType(val string) attribute.KeyValue {
116121
return attribute.Key(attr.ErrorType).String(val)
117122
}

pkg/app/request/span.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ const (
7676
DBMySQL
7777
)
7878

79+
const (
80+
HTTPSubtypeNone = 0 // http
81+
HTTPSubtypeGraphQL = 1 // http + graphql
82+
)
83+
7984
//nolint:cyclop
8085
func (t EventType) String() string {
8186
switch t {
@@ -159,6 +164,12 @@ type MessagingInfo struct {
159164
Partition int `json:"partition"`
160165
}
161166

167+
type GraphQL struct {
168+
Document string `json:"document"`
169+
OperationName string `json:"operationName"`
170+
OperationType string `json:"operationType"`
171+
}
172+
162173
// Span contains the information being submitted by the following nodes in the graph.
163174
// It enables comfortable handling of data from Go.
164175
// REMINDER: any attribute here must be also added to the functions SpanOTELGetters,
@@ -195,6 +206,7 @@ type Span struct {
195206
SQLCommand string `json:"-"`
196207
SQLError *SQLError `json:"-"`
197208
MessagingInfo *MessagingInfo `json:"-"`
209+
GraphQL *GraphQL `json:"-"`
198210

199211
// OverrideTraceName is set under some conditions, like spanmetrics reaching the maximum
200212
// cardinality for trace names.
@@ -217,7 +229,7 @@ type SpanAttributes map[string]string
217229
func spanAttributes(s *Span) SpanAttributes {
218230
switch s.Type {
219231
case EventTypeHTTP:
220-
return SpanAttributes{
232+
attrs := SpanAttributes{
221233
"method": s.Method,
222234
"status": strconv.Itoa(s.Status),
223235
"url": s.Path,
@@ -228,6 +240,12 @@ func spanAttributes(s *Span) SpanAttributes {
228240
"serverAddr": SpanHost(s),
229241
"serverPort": strconv.Itoa(s.HostPort),
230242
}
243+
if s.SubType == HTTPSubtypeGraphQL && s.GraphQL != nil {
244+
attrs["graphqlDocument"] = s.GraphQL.Document
245+
attrs["graphqlOperationName"] = s.GraphQL.OperationName
246+
attrs["graphqlOperationType"] = s.GraphQL.OperationType
247+
}
248+
return attrs
231249
case EventTypeHTTPClient:
232250
return SpanAttributes{
233251
"method": s.Method,
@@ -562,6 +580,14 @@ func (s *Span) TraceName() string {
562580
}
563581
switch s.Type {
564582
case EventTypeHTTP, EventTypeHTTPClient:
583+
if s.Type == EventTypeHTTP && s.SubType == HTTPSubtypeGraphQL && s.GraphQL != nil {
584+
if s.GraphQL.OperationType != "" {
585+
return "GraphQL " + s.GraphQL.OperationType
586+
} else {
587+
return "GraphQL Operation"
588+
}
589+
}
590+
565591
name := s.Method
566592
if s.Route != "" {
567593
name += " " + s.Route

pkg/app/request/span_getters.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ func spanOTELGetters(name attr.Name) (attributes.Getter[*Span, attribute.KeyValu
118118
getter = func(span *Span) attribute.KeyValue { return Job(span.Service.Job()) }
119119
case attr.Instance:
120120
getter = func(span *Span) attribute.KeyValue { return Job(span.Service.UID.Instance) }
121+
case attr.GraphQLDocument:
122+
getter = func(s *Span) attribute.KeyValue {
123+
if s.Type == EventTypeHTTP && s.SubType == HTTPSubtypeGraphQL && s.GraphQL != nil {
124+
return semconv.GraphqlDocument(s.GraphQL.Document)
125+
}
126+
return semconv.GraphqlDocument("")
127+
}
128+
case attr.GraphQLOperationName:
129+
getter = func(s *Span) attribute.KeyValue {
130+
if s.Type == EventTypeHTTP && s.SubType == HTTPSubtypeGraphQL && s.GraphQL != nil {
131+
return semconv.GraphqlOperationName(s.GraphQL.OperationName)
132+
}
133+
return semconv.GraphqlOperationName("")
134+
}
135+
case attr.GraphQLOperationType:
136+
getter = func(s *Span) attribute.KeyValue {
137+
if s.Type == EventTypeHTTP && s.SubType == HTTPSubtypeGraphQL && s.GraphQL != nil {
138+
return GraphqlOperationType(s.GraphQL.OperationType)
139+
}
140+
return GraphqlOperationType("")
141+
}
121142
}
122143
// default: unlike the Prometheus getters, we don't check here for service name nor k8s metadata
123144
// because they are already attributes of the Resource instead of the attributes.

pkg/config/ebpf_tracer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ type EBPFTracer struct {
105105

106106
// MongoDB requests cache size.
107107
MongoRequestsCacheSize int `yaml:"mongo_requests_cache_size" env:"OTEL_EBPF_BPF_MONGO_REQUESTS_CACHE_SIZE"`
108+
109+
// Configure data extraction/parsing based on protocol
110+
PayloadExtraction PayloadExtraction `yaml:"payload_extraction"`
108111
}
109112

110113
// Per-protocol data buffer size in bytes.

pkg/config/payload_extraction.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package config
5+
6+
type PayloadExtraction struct {
7+
HTTP HTTPConfig `yaml:"http"`
8+
}
9+
10+
type HTTPConfig struct {
11+
// GraphQL payload extraction and parsing
12+
GraphQL GraphQLConfig `yaml:"graphql"`
13+
}
14+
15+
type GraphQLConfig struct {
16+
// Enable GraphQL payload extraction and parsing
17+
Enabled bool `yaml:"enabled" env:"OTEL_EBPF_HTTP_GRAPHQL_ENABLED"`
18+
}

pkg/ebpf/common/common.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ type EBPFParseContext struct {
133133
postgresPreparedStatements *simplelru.LRU[postgresPreparedStatementsKey, string]
134134
postgresPortals *simplelru.LRU[postgresPortalsKey, string]
135135
kafkaTopicUUIDToName *simplelru.LRU[kafkaparser.UUID, string]
136+
payloadExtraction config.PayloadExtraction
136137
}
137138

138139
type EBPFEventContext struct {
@@ -157,6 +158,7 @@ func NewEBPFParseContext(cfg *config.EBPFTracer) *EBPFParseContext {
157158
postgresPortals *simplelru.LRU[postgresPortalsKey, string]
158159
kafkaTopicUUIDToName *simplelru.LRU[kafkaparser.UUID, string]
159160
mongoRequestCache PendingMongoDBRequests
161+
payloadExtraction config.PayloadExtraction
160162
)
161163

162164
h2c, _ := lru.New[uint64, h2Connection](1024 * 10)
@@ -192,6 +194,8 @@ func NewEBPFParseContext(cfg *config.EBPFTracer) *EBPFParseContext {
192194
}
193195

194196
mongoRequestCache = expirable.NewLRU[MongoRequestKey, *MongoRequestValue](cfg.MongoRequestsCacheSize, nil, 0)
197+
198+
payloadExtraction = cfg.PayloadExtraction
195199
}
196200

197201
return &EBPFParseContext{
@@ -203,6 +207,7 @@ func NewEBPFParseContext(cfg *config.EBPFTracer) *EBPFParseContext {
203207
postgresPreparedStatements: postgresPreparedStatements,
204208
postgresPortals: postgresPortals,
205209
kafkaTopicUUIDToName: kafkaTopicUUIDToName,
210+
payloadExtraction: payloadExtraction,
206211
}
207212
}
208213

@@ -404,3 +409,27 @@ func (connInfo *BPFConnInfo) reqHostInfo() (source, target string) {
404409

405410
return srcStr, dstStr
406411
}
412+
413+
func isClientEvent(et uint8) bool {
414+
switch request.EventType(et) {
415+
case request.EventTypeGRPCClient, request.EventTypeHTTPClient, request.EventTypeRedisClient,
416+
request.EventTypeKafkaClient, request.EventTypeSQLClient, request.EventTypeMongoClient,
417+
request.EventTypeFailedConnect:
418+
return true
419+
}
420+
421+
return false
422+
}
423+
424+
func directionByPacketType(pt uint8, isClient bool) uint8 {
425+
if isClient {
426+
if pt == packetTypeRequest {
427+
return directionSend
428+
}
429+
return directionRecv
430+
}
431+
if pt == packetTypeRequest {
432+
return directionRecv
433+
}
434+
return directionSend
435+
}

0 commit comments

Comments
 (0)