Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions components-rs/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ typedef struct ddog_Slice_CChar {
*/
typedef struct ddog_Slice_CChar ddog_CharSlice;

typedef struct ddog_Slice_U8 {
/**
* Should be non-null and suitably aligned for the underlying type. It is
* allowed but not recommended for the pointer to be null when the len is
* zero.
*/
const uint8_t *ptr;
/**
* The number of bytes that `.ptr` points to. Must be less than or equal
* to [isize::MAX].
*/
uintptr_t len;
} ddog_Slice_U8;

/**
* Use to represent arbitrary binary byte slices (e.g. encoded protobuf).
*/
typedef struct ddog_Slice_U8 ddog_ByteSlice;

typedef enum ddog_Option_Error_Tag {
DDOG_OPTION_ERROR_SOME_ERROR,
DDOG_OPTION_ERROR_NONE_ERROR,
Expand Down
27 changes: 27 additions & 0 deletions components-rs/sidecar.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,33 @@ ddog_CharSlice ddog_sidecar_dump(struct ddog_SidecarTransport **transport);
*/
ddog_CharSlice ddog_sidecar_stats(struct ddog_SidecarTransport **transport);

/**
* Forward a single FFE (Feature Flag Evaluation) exposure batch payload to
* the sidecar. The sidecar asynchronously POSTs it to the agent EVP proxy
* at `/evp_proxy/v2/api/v2/exposures`.
*
* A null or empty `payload` is a no-op.
*/
ddog_MaybeError ddog_sidecar_send_ffe_exposures(struct ddog_SidecarTransport **transport,
const struct ddog_InstanceId *instance_id,
const ddog_QueueId *queue_id,
ddog_CharSlice payload);

/**
* Forward a single FFE evaluation-metrics batch payload (OTLP/protobuf,
* encoded by the PHP-side `OtlpMetricEncoder`) to the sidecar. The sidecar
* asynchronously POSTs it as `application/x-protobuf` to the configured
* OTLP HTTP metrics intake (`endpoint` argument, typically the value of
* `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`).
*
* A null/empty `endpoint` or `payload` is a no-op.
*/
ddog_MaybeError ddog_sidecar_send_ffe_metrics(struct ddog_SidecarTransport **transport,
const struct ddog_InstanceId *instance_id,
const ddog_QueueId *queue_id,
ddog_CharSlice endpoint,
ddog_ByteSlice payload);

/**
* Send a DogStatsD "count" metric.
*/
Expand Down
47 changes: 0 additions & 47 deletions docs/php-ffe-stack/README.md

This file was deleted.

16 changes: 0 additions & 16 deletions docs/php-ffe-stack/stack-pr3909.mmd

This file was deleted.

Binary file removed docs/php-ffe-stack/stack-pr3909.png
Binary file not shown.
51 changes: 0 additions & 51 deletions docs/php-ffe-stack/system-pr3909.mmd

This file was deleted.

Binary file removed docs/php-ffe-stack/system-pr3909.png
Binary file not shown.
22 changes: 22 additions & 0 deletions ext/ddtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2784,6 +2784,28 @@ PHP_FUNCTION(DDTrace_dogstatsd_count) {
RETURN_NULL();
}

PHP_FUNCTION(DDTrace_send_ffe_exposures) {
zend_string *payload;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(payload)
ZEND_PARSE_PARAMETERS_END();

RETURN_BOOL(ddtrace_sidecar_send_ffe_exposures(payload));
}

PHP_FUNCTION(DDTrace_send_ffe_metrics) {
zend_string *endpoint;
zend_string *payload;

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR(endpoint)
Z_PARAM_STR(payload)
ZEND_PARSE_PARAMETERS_END();

RETURN_BOOL(ddtrace_sidecar_send_ffe_metrics(endpoint, payload));
}

PHP_FUNCTION(DDTrace_dogstatsd_distribution) {
zend_string *metric;
double value;
Expand Down
34 changes: 34 additions & 0 deletions ext/ddtrace.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,40 @@ function dogstatsd_histogram(string $metric, float $value, array $tags = []): vo
*/
function dogstatsd_set(string $metric, int $value, array $tags = []): void {}

/**
* @internal Datadog-owned bridge adapters only — used by
* `DDTrace\FeatureFlags\Internal\Exposure\SidecarExposureTransport`.
*
* Forward an FFE (Feature Flag Evaluation) exposure batch payload to the
* libdatadog sidecar. The sidecar asynchronously POSTs the JSON batch to
* the agent EVP proxy at `/evp_proxy/v2/api/v2/exposures`.
*
* Fire-and-forget: the sidecar handles retries/backoff. An empty payload
* is a no-op.
*
* @param string $payloadJson Server-side batched exposure JSON envelope.
* @return bool true if enqueued for sidecar dispatch, false otherwise.
*/
function send_ffe_exposures(string $payloadJson): bool {}

/**
* @internal Datadog-owned bridge adapters only — used by
* `DDTrace\FeatureFlags\Internal\Metric\SidecarOtlpMetricsTransport`.
*
* Forward an FFE evaluation-metrics batch payload (OTLP/protobuf, encoded
* by the PHP-side `OtlpMetricEncoder`) to the libdatadog sidecar. The
* sidecar asynchronously POSTs it as `application/x-protobuf` to the
* configured OTLP HTTP metrics intake (typically the value of
* `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`).
*
* Fire-and-forget. Empty endpoint or payload is a no-op.
*
* @param string $endpoint OTLP HTTP metrics endpoint URL.
* @param string $payloadBytes Encoded OTLP/protobuf payload bytes.
* @return bool true if enqueued for sidecar dispatch, false otherwise.
*/
function send_ffe_metrics(string $endpoint, string $payloadBytes): bool {}

/**
* Store data tied to a resource. Behaves like a weakmap, i.e. data is freed when the associated resource is freed.
*
Expand Down
13 changes: 13 additions & 0 deletions ext/ddtrace_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ ZEND_END_ARG_INFO()

#define arginfo_DDTrace_dogstatsd_set arginfo_DDTrace_dogstatsd_count

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_DDTrace_send_ffe_exposures, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, payloadJson, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_DDTrace_send_ffe_metrics, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, endpoint, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, payloadBytes, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_DDTrace_resource_weak_store, 0, 3, IS_VOID, 0)
ZEND_ARG_TYPE_INFO(0, resource, IS_MIXED, 0)
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
Expand Down Expand Up @@ -406,6 +415,8 @@ ZEND_FUNCTION(DDTrace_dogstatsd_distribution);
ZEND_FUNCTION(DDTrace_dogstatsd_gauge);
ZEND_FUNCTION(DDTrace_dogstatsd_histogram);
ZEND_FUNCTION(DDTrace_dogstatsd_set);
ZEND_FUNCTION(DDTrace_send_ffe_exposures);
ZEND_FUNCTION(DDTrace_send_ffe_metrics);
ZEND_FUNCTION(DDTrace_resource_weak_store);
ZEND_FUNCTION(DDTrace_resource_weak_get);
ZEND_FUNCTION(DDTrace_are_endpoints_collected);
Expand Down Expand Up @@ -505,6 +516,8 @@ static const zend_function_entry ext_functions[] = {
ZEND_RAW_FENTRY(ZEND_NS_NAME("DDTrace", "dogstatsd_gauge"), zif_DDTrace_dogstatsd_gauge, arginfo_DDTrace_dogstatsd_gauge, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("DDTrace", "dogstatsd_histogram"), zif_DDTrace_dogstatsd_histogram, arginfo_DDTrace_dogstatsd_histogram, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("DDTrace", "dogstatsd_set"), zif_DDTrace_dogstatsd_set, arginfo_DDTrace_dogstatsd_set, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("DDTrace", "send_ffe_exposures"), zif_DDTrace_send_ffe_exposures, arginfo_DDTrace_send_ffe_exposures, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("DDTrace", "send_ffe_metrics"), zif_DDTrace_send_ffe_metrics, arginfo_DDTrace_send_ffe_metrics, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("DDTrace", "resource_weak_store"), zif_DDTrace_resource_weak_store, arginfo_DDTrace_resource_weak_store, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("DDTrace", "resource_weak_get"), zif_DDTrace_resource_weak_get, arginfo_DDTrace_resource_weak_get, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("DDTrace", "are_endpoints_collected"), zif_DDTrace_are_endpoints_collected, arginfo_DDTrace_are_endpoints_collected, 0, NULL, NULL)
Expand Down
32 changes: 32 additions & 0 deletions ext/sidecar.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,38 @@ void ddtrace_sidecar_dogstatsd_count(zend_string *metric, zend_long value, zval
ddog_Vec_Tag_drop(vec);
}

bool ddtrace_sidecar_send_ffe_exposures(zend_string *payload_json) {
if (!DDTRACE_G(sidecar) || payload_json == NULL || ZSTR_LEN(payload_json) == 0) {
return false;
}
return ddtrace_ffi_try(
"Failed sending FFE exposure batch to sidecar",
ddog_sidecar_send_ffe_exposures(
&DDTRACE_G(sidecar),
ddtrace_sidecar_instance_id,
&DDTRACE_G(sidecar_queue_id),
dd_zend_string_to_CharSlice(payload_json)));
}

bool ddtrace_sidecar_send_ffe_metrics(zend_string *endpoint, zend_string *payload_bytes) {
if (!DDTRACE_G(sidecar) || endpoint == NULL || ZSTR_LEN(endpoint) == 0
|| payload_bytes == NULL || ZSTR_LEN(payload_bytes) == 0) {
return false;
}
ddog_ByteSlice payload = {
.ptr = (const uint8_t *) ZSTR_VAL(payload_bytes),
.len = ZSTR_LEN(payload_bytes),
};
return ddtrace_ffi_try(
"Failed sending FFE metrics batch to sidecar",
ddog_sidecar_send_ffe_metrics(
&DDTRACE_G(sidecar),
ddtrace_sidecar_instance_id,
&DDTRACE_G(sidecar_queue_id),
dd_zend_string_to_CharSlice(endpoint),
payload));
}

void ddtrace_sidecar_dogstatsd_distribution(zend_string *metric, double value, zval *tags) {
if (!DDTRACE_G(sidecar) || !get_DD_INTEGRATION_METRICS_ENABLED()) {
return;
Expand Down
3 changes: 3 additions & 0 deletions ext/sidecar.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ void ddtrace_sidecar_dogstatsd_gauge(zend_string *metric, double value, zval *ta
void ddtrace_sidecar_dogstatsd_histogram(zend_string *metric, double value, zval *tags);
void ddtrace_sidecar_dogstatsd_set(zend_string *metric, zend_long value, zval *tags);

bool ddtrace_sidecar_send_ffe_exposures(zend_string *payload_json);
bool ddtrace_sidecar_send_ffe_metrics(zend_string *endpoint, zend_string *payload_bytes);

bool ddtrace_alter_test_session_token(zval *old_value, zval *new_value, zend_string *new_str);

static inline ddog_CharSlice dd_zend_string_to_CharSlice(zend_string *str) {
Expand Down
Loading
Loading