Skip to content

Commit 91222ad

Browse files
Leiyksbwoebi
andauthored
feat: reduce telemetry sent (#3316)
* feat: update libdatadog version Signed-off-by: Alexandre Rulleau <[email protected]> * feat: update telemetry calls Signed-off-by: Alexandre Rulleau <[email protected]> * feat(ext): move filtering code to Rust side Signed-off-by: Alexandre Rulleau <[email protected]> * chore: fix tests Signed-off-by: Alexandre Rulleau <[email protected]> * chore: temporary deactivate flaky test Signed-off-by: Alexandre Rulleau <[email protected]> * chore: fix segfault Signed-off-by: Alexandre Rulleau <[email protected]> * chore: update libdatadog Signed-off-by: Alexandre Rulleau <[email protected]> * chore: clean code Signed-off-by: Alexandre Rulleau <[email protected]> * test: update integration tests Signed-off-by: Alexandre Rulleau <[email protected]> * feat: remove needs for version Signed-off-by: Alexandre Rulleau <[email protected]> * feat: add telemetry caching system for SHM read operation Signed-off-by: Alexandre Rulleau <[email protected]> * feat(sidecar: telemetry): handle config buffering Signed-off-by: Alexandre Rulleau <[email protected]> * Fix windows compilation Signed-off-by: Bob Weinand <[email protected]> --------- Signed-off-by: Alexandre Rulleau <[email protected]> Signed-off-by: Bob Weinand <[email protected]> Co-authored-by: Bob Weinand <[email protected]>
1 parent 2e1da6a commit 91222ad

32 files changed

Lines changed: 616 additions & 197 deletions

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components-rs/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ regex = "1.10.5"
4646
regex-automata = "0.4.5"
4747
http = "1.0"
4848
libc = "0.2"
49+
bincode = { version = "1.3.3" }
50+
hashbrown = "0.15"
4951

5052
[build-dependencies]
5153
cbindgen = "0.27"

components-rs/common.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ typedef struct ddog_DebuggerPayload ddog_DebuggerPayload;
396396

397397
typedef struct ddog_DslString ddog_DslString;
398398

399+
typedef struct ddog_HashMap_ShmCacheKey__ShmCache ddog_HashMap_ShmCacheKey__ShmCache;
400+
399401
/**
400402
* `InstanceId` is a structure that holds session and runtime identifiers.
401403
*/
@@ -603,6 +605,8 @@ typedef struct ddog_Vec_DebuggerPayload {
603605
uintptr_t capacity;
604606
} ddog_Vec_DebuggerPayload;
605607

608+
typedef struct ddog_HashMap_ShmCacheKey__ShmCache ddog_ShmCacheMap;
609+
606610
/**
607611
* Holds the raw parts of a Rust Vec; it should only be created from Rust,
608612
* never from C.
@@ -836,6 +840,13 @@ typedef struct ddog_ContextKey {
836840
enum ddog_MetricType _1;
837841
} ddog_ContextKey;
838842

843+
typedef struct ddog_SpanBytes ddog_SpanBytes;
844+
typedef struct ddog_SpanLinkBytes ddog_SpanLinkBytes;
845+
typedef struct ddog_SpanEventBytes ddog_SpanEventBytes;
846+
typedef struct ddog_AttributeAnyValueBytes ddog_AttributeAnyValueBytes;
847+
typedef struct ddog_AttributeArrayValueBytes ddog_AttributeArrayValueBytes;
848+
849+
839850
typedef struct ddog_AgentInfoReader ddog_AgentInfoReader;
840851

841852
typedef struct ddog_AgentRemoteConfigReader ddog_AgentRemoteConfigReader;
@@ -881,6 +892,40 @@ typedef struct ddog_TracerHeaderTags {
881892
bool client_computed_stats;
882893
} ddog_TracerHeaderTags;
883894

895+
/**
896+
* Holds the raw parts of a Rust Vec; it should only be created from Rust,
897+
* never from C.
898+
*/
899+
typedef struct ddog_Vec_SpanBytes {
900+
const ddog_SpanBytes *ptr;
901+
uintptr_t len;
902+
uintptr_t capacity;
903+
} ddog_Vec_SpanBytes;
904+
905+
typedef struct ddog_Vec_SpanBytes ddog_TraceBytes;
906+
907+
/**
908+
* Holds the raw parts of a Rust Vec; it should only be created from Rust,
909+
* never from C.
910+
*/
911+
typedef struct ddog_Vec_TraceBytes {
912+
const ddog_TraceBytes *ptr;
913+
uintptr_t len;
914+
uintptr_t capacity;
915+
} ddog_Vec_TraceBytes;
916+
917+
typedef struct ddog_Vec_TraceBytes ddog_TracesBytes;
918+
919+
typedef struct ddog_SenderParameters {
920+
struct ddog_TracerHeaderTags tracer_headers_tags;
921+
struct ddog_SidecarTransport *transport;
922+
struct ddog_InstanceId *instance_id;
923+
uintptr_t limit;
924+
int64_t n_requests;
925+
int64_t buffer_size;
926+
ddog_CharSlice url;
927+
} ddog_SenderParameters;
928+
884929
typedef enum ddog_crasht_BuildIdType {
885930
DDOG_CRASHT_BUILD_ID_TYPE_GNU,
886931
DDOG_CRASHT_BUILD_ID_TYPE_GO,
@@ -1098,6 +1143,9 @@ typedef struct ddog_crasht_Config {
10981143
struct ddog_crasht_Slice_I32 signals;
10991144
/**
11001145
* Timeout in milliseconds before the signal handler starts tearing things down to return.
1146+
* If 0, uses the default timeout as specified in
1147+
* `datadog_crashtracker::shared::constants::DD_CRASHTRACK_DEFAULT_TIMEOUT`. Otherwise, uses
1148+
* the specified timeout value.
11011149
* This is given as a uint32_t, but the actual timeout needs to fit inside of an i32 (max
11021150
* 2^31-1). This is a limitation of the various interfaces used to guarantee the timeout.
11031151
*/

components-rs/crashtracker.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,16 @@ struct ddog_VoidResult ddog_crasht_CrashInfoBuilder_with_uuid(struct ddog_crasht
679679
DDOG_CHECK_RETURN
680680
struct ddog_VoidResult ddog_crasht_CrashInfoBuilder_with_uuid_random(struct ddog_crasht_Handle_CrashInfoBuilder *builder);
681681

682+
/**
683+
* # Safety
684+
* The `crash_info` can be null, but if non-null it must point to a Builder made by this module,
685+
* which has not previously been dropped.
686+
* The CharSlice must be valid.
687+
*/
688+
DDOG_CHECK_RETURN
689+
struct ddog_VoidResult ddog_crasht_CrashInfoBuilder_with_message(struct ddog_crasht_Handle_CrashInfoBuilder *builder,
690+
ddog_CharSlice message);
691+
682692
/**
683693
* Create a new StackFrame, and returns an opaque reference to it.
684694
* # Safety

components-rs/ddtrace.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ struct ddog_Endpoint *ddtrace_parse_agent_url(ddog_CharSlice url);
157157

158158
ddog_Configurator *ddog_library_configurator_new_dummy(bool debug_logs, ddog_CharSlice language);
159159

160+
int posix_spawn_file_actions_addchdir_np(void *file_actions, const char *path);
161+
160162
bool ddog_shall_log(enum ddog_Log category);
161163

162164
void ddog_set_error_log_level(bool once);
@@ -277,4 +279,20 @@ void ddog_sidecar_telemetry_add_integration_log_buffer(enum ddog_Log category,
277279
struct ddog_SidecarActionsBuffer *buffer,
278280
ddog_CharSlice log);
279281

282+
ddog_ShmCacheMap *ddog_sidecar_telemetry_cache_new(void);
283+
284+
void ddog_sidecar_telemetry_cache_drop(ddog_ShmCacheMap*);
285+
286+
bool ddog_sidecar_telemetry_config_sent(const ddog_ShmCacheMap *cache,
287+
ddog_CharSlice service,
288+
ddog_CharSlice env);
289+
290+
ddog_MaybeError ddog_sidecar_telemetry_filter_flush(struct ddog_SidecarTransport **transport,
291+
const struct ddog_InstanceId *instance_id,
292+
const ddog_QueueId *queue_id,
293+
struct ddog_SidecarActionsBuffer *buffer,
294+
ddog_ShmCacheMap *cache,
295+
ddog_CharSlice service,
296+
ddog_CharSlice env);
297+
280298
#endif /* DDTRACE_PHP_H */

components-rs/live-debugger.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ void ddog_evaluated_value_drop(struct ddog_InternalIntermediateValue*);
3535
struct ddog_VoidCollection ddog_evaluated_value_into_unmanaged_string(struct ddog_InternalIntermediateValue *value,
3636
void *context);
3737

38+
/**
39+
* # Safety
40+
* The `json` must be a valid UTF-8 string.
41+
*/
3842
struct ddog_LiveDebuggingParseResult ddog_parse_live_debugger_json(ddog_CharSlice json);
3943

4044
void ddog_drop_live_debugger_parse_result(struct ddog_LiveDebuggingParseResult);

components-rs/sidecar.h

Lines changed: 147 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4-
54
#ifndef DDOG_SIDECAR_H
65
#define DDOG_SIDECAR_H
76

@@ -150,23 +149,20 @@ ddog_MaybeError ddog_sidecar_telemetry_addIntegration(struct ddog_SidecarTranspo
150149
ddog_CharSlice integration_version,
151150
bool integration_enabled);
152151

153-
/**
154-
* Registers a service and flushes any queued actions.
155-
*/
156-
ddog_MaybeError ddog_sidecar_telemetry_flushServiceData(struct ddog_SidecarTransport **transport,
157-
const struct ddog_InstanceId *instance_id,
158-
const ddog_QueueId *queue_id,
159-
const struct ddog_RuntimeMetadata *runtime_meta,
160-
ddog_CharSlice service_name,
161-
ddog_CharSlice env_name);
162-
163152
/**
164153
* Enqueues a list of actions to be performed.
165154
*/
166155
ddog_MaybeError ddog_sidecar_lifecycle_end(struct ddog_SidecarTransport **transport,
167156
const struct ddog_InstanceId *instance_id,
168157
const ddog_QueueId *queue_id);
169158

159+
/**
160+
* Enqueues a list of actions to be performed.
161+
*/
162+
ddog_MaybeError ddog_sidecar_application_remove(struct ddog_SidecarTransport **transport,
163+
const struct ddog_InstanceId *instance_id,
164+
const ddog_QueueId *queue_id);
165+
170166
/**
171167
* Flushes the telemetry data.
172168
*/
@@ -187,6 +183,7 @@ ddog_MaybeError ddog_sidecar_session_set_config(struct ddog_SidecarTransport **t
187183
const struct ddog_Endpoint *agent_endpoint,
188184
const struct ddog_Endpoint *dogstatsd_endpoint,
189185
ddog_CharSlice language,
186+
ddog_CharSlice language_version,
190187
ddog_CharSlice tracer_version,
191188
uint32_t flush_interval_milliseconds,
192189
uint32_t remote_config_poll_interval_millis,
@@ -200,6 +197,7 @@ ddog_MaybeError ddog_sidecar_session_set_config(struct ddog_SidecarTransport **t
200197
uintptr_t remote_config_products_count,
201198
const enum ddog_RemoteConfigCapabilities *remote_config_capabilities,
202199
uintptr_t remote_config_capabilities_count,
200+
bool remote_config_enabled,
203201
bool is_fork);
204202

205203
/**
@@ -251,13 +249,13 @@ ddog_MaybeError ddog_sidecar_send_debugger_diagnostics(struct ddog_SidecarTransp
251249
ddog_QueueId queue_id,
252250
struct ddog_DebuggerPayload diagnostics_payload);
253251

254-
ddog_MaybeError ddog_sidecar_set_remote_config_data(struct ddog_SidecarTransport **transport,
255-
const struct ddog_InstanceId *instance_id,
256-
const ddog_QueueId *queue_id,
257-
ddog_CharSlice service_name,
258-
ddog_CharSlice env_name,
259-
ddog_CharSlice app_version,
260-
const struct ddog_Vec_Tag *global_tags);
252+
ddog_MaybeError ddog_sidecar_set_universal_service_tags(struct ddog_SidecarTransport **transport,
253+
const struct ddog_InstanceId *instance_id,
254+
const ddog_QueueId *queue_id,
255+
ddog_CharSlice service_name,
256+
ddog_CharSlice env_name,
257+
ddog_CharSlice app_version,
258+
const struct ddog_Vec_Tag *global_tags);
261259

262260
/**
263261
* Dumps the current state of the sidecar.
@@ -348,9 +346,140 @@ struct ddog_AgentInfoReader *ddog_get_agent_info_reader(const struct ddog_Endpoi
348346
*/
349347
ddog_CharSlice ddog_get_agent_info_env(struct ddog_AgentInfoReader *reader, bool *changed);
350348

349+
void ddog_send_traces_to_sidecar(ddog_TracesBytes *traces,
350+
struct ddog_SenderParameters *parameters);
351+
351352
/**
352353
* Drops the agent info reader.
353354
*/
354355
void ddog_drop_agent_info_reader(struct ddog_AgentInfoReader*);
355356

357+
ddog_TracesBytes *ddog_get_traces(void);
358+
359+
void ddog_free_traces(ddog_TracesBytes *_traces);
360+
361+
uintptr_t ddog_get_traces_size(const ddog_TracesBytes *traces);
362+
363+
ddog_TraceBytes *ddog_get_trace(ddog_TracesBytes *traces, uintptr_t index);
364+
365+
ddog_TraceBytes *ddog_traces_new_trace(ddog_TracesBytes *traces);
366+
367+
uintptr_t ddog_get_trace_size(const ddog_TraceBytes *trace);
368+
369+
ddog_SpanBytes *ddog_get_span(ddog_TraceBytes *trace, uintptr_t index);
370+
371+
ddog_SpanBytes *ddog_trace_new_span(ddog_TraceBytes *trace);
372+
373+
ddog_SpanBytes *ddog_trace_new_span_with_capacities(ddog_TraceBytes *trace,
374+
uintptr_t meta_size,
375+
uintptr_t metrics_size);
376+
377+
ddog_CharSlice ddog_span_debug_log(const ddog_SpanBytes *span);
378+
379+
void ddog_free_charslice(ddog_CharSlice slice);
380+
381+
void ddog_set_span_service(ddog_SpanBytes *span, ddog_CharSlice slice);
382+
383+
ddog_CharSlice ddog_get_span_service(ddog_SpanBytes *span);
384+
385+
void ddog_set_span_name(ddog_SpanBytes *span, ddog_CharSlice slice);
386+
387+
ddog_CharSlice ddog_get_span_name(ddog_SpanBytes *span);
388+
389+
void ddog_set_span_resource(ddog_SpanBytes *span, ddog_CharSlice slice);
390+
391+
ddog_CharSlice ddog_get_span_resource(ddog_SpanBytes *span);
392+
393+
void ddog_set_span_type(ddog_SpanBytes *span, ddog_CharSlice slice);
394+
395+
ddog_CharSlice ddog_get_span_type(ddog_SpanBytes *span);
396+
397+
void ddog_set_span_trace_id(ddog_SpanBytes *span, uint64_t value);
398+
399+
uint64_t ddog_get_span_trace_id(ddog_SpanBytes *span);
400+
401+
void ddog_set_span_id(ddog_SpanBytes *span, uint64_t value);
402+
403+
uint64_t ddog_get_span_id(ddog_SpanBytes *span);
404+
405+
void ddog_set_span_parent_id(ddog_SpanBytes *span, uint64_t value);
406+
407+
uint64_t ddog_get_span_parent_id(ddog_SpanBytes *span);
408+
409+
void ddog_set_span_start(ddog_SpanBytes *span, int64_t value);
410+
411+
int64_t ddog_get_span_start(ddog_SpanBytes *span);
412+
413+
void ddog_set_span_duration(ddog_SpanBytes *span, int64_t value);
414+
415+
int64_t ddog_get_span_duration(ddog_SpanBytes *span);
416+
417+
void ddog_set_span_error(ddog_SpanBytes *span, int32_t value);
418+
419+
int32_t ddog_get_span_error(ddog_SpanBytes *span);
420+
421+
void ddog_add_span_meta(ddog_SpanBytes *span, ddog_CharSlice key, ddog_CharSlice value);
422+
423+
void ddog_del_span_meta(ddog_SpanBytes *span, ddog_CharSlice key);
424+
425+
ddog_CharSlice ddog_get_span_meta(ddog_SpanBytes *span, ddog_CharSlice key);
426+
427+
bool ddog_has_span_meta(ddog_SpanBytes *span, ddog_CharSlice key);
428+
429+
ddog_CharSlice *ddog_span_meta_get_keys(ddog_SpanBytes *span, uintptr_t *out_count);
430+
431+
void ddog_add_span_metrics(ddog_SpanBytes *span, ddog_CharSlice key, double val);
432+
433+
void ddog_del_span_metrics(ddog_SpanBytes *span, ddog_CharSlice key);
434+
435+
bool ddog_get_span_metrics(ddog_SpanBytes *span, ddog_CharSlice key, double *result);
436+
437+
bool ddog_has_span_metrics(ddog_SpanBytes *span, ddog_CharSlice key);
438+
439+
ddog_CharSlice *ddog_span_metrics_get_keys(ddog_SpanBytes *span, uintptr_t *out_count);
440+
441+
void ddog_add_span_meta_struct(ddog_SpanBytes *span, ddog_CharSlice key, ddog_CharSlice val);
442+
443+
void ddog_del_span_meta_struct(ddog_SpanBytes *span, ddog_CharSlice key);
444+
445+
ddog_CharSlice ddog_get_span_meta_struct(ddog_SpanBytes *span, ddog_CharSlice key);
446+
447+
bool ddog_has_span_meta_struct(ddog_SpanBytes *span, ddog_CharSlice key);
448+
449+
ddog_CharSlice *ddog_span_meta_struct_get_keys(ddog_SpanBytes *span, uintptr_t *out_count);
450+
451+
void ddog_span_free_keys_ptr(ddog_CharSlice *keys_ptr, uintptr_t count);
452+
453+
ddog_SpanLinkBytes *ddog_span_new_link(ddog_SpanBytes *span);
454+
455+
void ddog_set_link_tracestate(ddog_SpanLinkBytes *link, ddog_CharSlice slice);
456+
457+
void ddog_set_link_trace_id(ddog_SpanLinkBytes *link, uint64_t value);
458+
459+
void ddog_set_link_trace_id_high(ddog_SpanLinkBytes *link, uint64_t value);
460+
461+
void ddog_set_link_span_id(ddog_SpanLinkBytes *link, uint64_t value);
462+
463+
void ddog_set_link_flags(ddog_SpanLinkBytes *link, uint32_t value);
464+
465+
void ddog_add_link_attributes(ddog_SpanLinkBytes *link, ddog_CharSlice key, ddog_CharSlice val);
466+
467+
ddog_SpanEventBytes *ddog_span_new_event(ddog_SpanBytes *span);
468+
469+
void ddog_set_event_name(ddog_SpanEventBytes *event, ddog_CharSlice slice);
470+
471+
void ddog_set_event_time(ddog_SpanEventBytes *event, uint64_t val);
472+
473+
void ddog_add_event_attributes_str(ddog_SpanEventBytes *event,
474+
ddog_CharSlice key,
475+
ddog_CharSlice val);
476+
477+
void ddog_add_event_attributes_bool(ddog_SpanEventBytes *event, ddog_CharSlice key, bool val);
478+
479+
void ddog_add_event_attributes_int(ddog_SpanEventBytes *event, ddog_CharSlice key, int64_t val);
480+
481+
void ddog_add_event_attributes_float(ddog_SpanEventBytes *event, ddog_CharSlice key, double val);
482+
483+
ddog_CharSlice ddog_serialize_trace_into_c_string(ddog_TraceBytes *trace);
484+
356485
#endif /* DDOG_SIDECAR_H */

0 commit comments

Comments
 (0)