Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions Couchbase/BinaryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $value, $options) {
$this->name,
$id,
$value,
AppendOptions::export($options)
AppendOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new MutationResult($response);
}
Expand Down Expand Up @@ -143,7 +144,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $value, $options) {
$this->name,
$id,
$value,
PrependOptions::export($options)
PrependOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new MutationResult($response);
}
Expand Down Expand Up @@ -177,7 +179,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $options) {
$this->scopeName,
$this->name,
$id,
IncrementOptions::export($options)
IncrementOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new CounterResult($response);
}
Expand Down Expand Up @@ -211,7 +214,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $options) {
$this->scopeName,
$this->name,
$id,
DecrementOptions::export($options)
DecrementOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new CounterResult($response);
}
Expand Down
18 changes: 13 additions & 5 deletions Couchbase/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function (ObservabilityHandler $obsHandler) use ($statement, $options) {
$obsHandler->addQueryStatement($statement, $options);

$function = COUCHBASE_EXTENSION_NAMESPACE . '\\query';
$result = $function($this->core, $statement, QueryOptions::export($options));
$result = $function($this->core, $statement, QueryOptions::export($options), $obsHandler->getCoreSpansArray());

return new QueryResult($result, QueryOptions::getTranscoder($options));
}
Expand Down Expand Up @@ -221,7 +221,7 @@ function (ObservabilityHandler $obsHandler) use ($statement, $options) {
$obsHandler->addQueryStatement($statement, $options);

$function = COUCHBASE_EXTENSION_NAMESPACE . '\\analyticsQuery';
$result = $function($this->core, $statement, AnalyticsOptions::export($options));
$result = $function($this->core, $statement, AnalyticsOptions::export($options), $obsHandler->getCoreSpansArray());

return new AnalyticsResult($result, AnalyticsOptions::getTranscoder($options));
}
Expand All @@ -248,7 +248,7 @@ function (ObservabilityHandler $obsHandler) use ($indexName, $query, $options) {
$obsHandler->addService(ObservabilityConstants::ATTR_VALUE_SERVICE_SEARCH);

$function = COUCHBASE_EXTENSION_NAMESPACE . '\\searchQuery';
$result = $function($this->core, $indexName, json_encode($query), SearchOptions::export($options));
$result = $function($this->core, $indexName, json_encode($query), SearchOptions::export($options), $obsHandler->getCoreSpansArray());

return new SearchResult($result);
}
Expand Down Expand Up @@ -283,13 +283,21 @@ function (ObservabilityHandler $obsHandler) use ($indexName, $request, $options)

if (!$exportedRequest['vectorSearch']) {
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\searchQuery';
$result = $function($this->core, $indexName, json_encode($query), $exportedOptions);
$result = $function($this->core, $indexName, json_encode($query), $exportedOptions, $obsHandler->getCoreSpansArray());
return new SearchResult($result);
}

$vectorSearch = $exportedRequest['vectorSearch'];
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\vectorSearch';
$result = $function($this->core, $indexName, json_encode($query), json_encode($vectorSearch), $exportedOptions, VectorSearchOptions::export($vectorSearch->options()));
$result = $function(
$this->core,
$indexName,
json_encode($query),
json_encode($vectorSearch),
$exportedOptions,
VectorSearchOptions::export($vectorSearch->options()),
$obsHandler->getCoreSpansArray()
);
return new SearchResult($result);
}
);
Expand Down
37 changes: 37 additions & 0 deletions Couchbase/ClusterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,46 @@ public function export(): array
'loggingMeterOptions' => $this->loggingMeterOptions == null ? null : $this->loggingMeterOptions->export(),
'appTelemetryConfiguration' =>
$this->appTelemetryConfiguration == null ? null : $this->appTelemetryConfiguration->export(),
'enableCoreTracing' => $this->enableCoreTracing(),
'enableCoreMetrics' => $this->enableCoreMetrics(),
'bufferCoreSpans' => $this->bufferCoreSpans(),
];
}

private function enableCoreTracing(): bool
{
if (!is_null($this->enableTracing) && !$this->enableTracing) {
// enableTracing takes precedence over the tracer
return false;
}
// We don't need tracing in the C++ core if the PHP tracer is the NoopTracer.
// We _do_ need core tracing if the PHP tracer is an external tracing, to buffer the core spans.
return is_null($this->tracer) || !($this->tracer instanceof NoopTracer);
}

private function enableCoreMetrics(): bool
{
if (!is_null($this->enableMetrics) && !$this->enableMetrics) {
// enableMetrics take precedence over the meter
return false;
}
// We only need metrics in the core when using the LoggingMeter.
// The logic for all other metrics is entirely on the wrapper side.
// The default (null) - meter is the LoggingMeter)
return is_null($this->meter) || $this->meter instanceof LoggingMeter;
}

private function bufferCoreSpans(): bool
{
if (!is_null($this->enableTracing) && !$this->enableTracing) {
return false;
}
// We need to buffer core spans and return them alongside the result, if using an external tracer.
return !is_null($this->tracer)
&& !($this->tracer instanceof NoopTracer)
&& !($this->tracer instanceof ThresholdLoggingTracer);
}

/**
* @param ClusterOptions|null $options
* @return ?RequestTracer
Expand Down
48 changes: 32 additions & 16 deletions Couchbase/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $options) {
$this->scopeName,
$this->name,
$id,
GetOptions::export($options)
GetOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new GetResult($response, GetOptions::getTranscoder($options));
}
Expand Down Expand Up @@ -175,7 +176,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $options) {
$this->scopeName,
$this->name,
$id,
ExistsOptions::export($options)
ExistsOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new ExistsResult($response);
}
Expand Down Expand Up @@ -210,7 +212,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $lockTimeSeconds, $options
$this->name,
$id,
$lockTimeSeconds,
GetAndLockOptions::export($options)
GetAndLockOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new GetResult($response, GetAndLockOptions::getTranscoder($options));
}
Expand Down Expand Up @@ -245,7 +248,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $expiry, $options) {
$this->name,
$id,
$expirySeconds,
GetAndTouchOptions::export($options)
GetAndTouchOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new GetResult($response, GetAndTouchOptions::getTranscoder($options));
}
Expand Down Expand Up @@ -278,7 +282,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $options) {
$this->scopeName,
$this->name,
$id,
GetAnyReplicaOptions::export($options)
GetAnyReplicaOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new GetReplicaResult($response, GetAnyReplicaOptions::getTranscoder($options));
}
Expand Down Expand Up @@ -310,7 +315,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $options) {
$this->scopeName,
$this->name,
$id,
GetAllReplicasOptions::export($options)
GetAllReplicasOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return array_map(
function (array $response) use ($options) {
Expand Down Expand Up @@ -355,7 +361,8 @@ function () use ($options, $value) {
$id,
$encoded[0],
$encoded[1],
UpsertOptions::export($options)
UpsertOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new MutationResult($response);
}
Expand Down Expand Up @@ -396,7 +403,8 @@ function () use ($options, $value) {
$id,
$encoded[0],
$encoded[1],
InsertOptions::export($options)
InsertOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new MutationResult($response);
}
Expand Down Expand Up @@ -438,7 +446,8 @@ function () use ($options, $value) {
$id,
$encoded[0],
$encoded[1],
ReplaceOptions::export($options)
ReplaceOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new MutationResult($response);
}
Expand Down Expand Up @@ -473,7 +482,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $options) {
$this->scopeName,
$this->name,
$id,
RemoveOptions::export($options)
RemoveOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new MutationResult($response);
}
Expand Down Expand Up @@ -509,7 +519,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $cas, $options) {
$this->name,
$id,
$cas,
UnlockOptions::export($options)
UnlockOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new Result($response);
}
Expand Down Expand Up @@ -544,7 +555,8 @@ function (ObservabilityHandler $obsHandler) use ($id, $expiry, $options) {
$this->name,
$id,
$expirySeconds,
TouchOptions::export($options)
TouchOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new MutationResult($response);
}
Expand Down Expand Up @@ -587,7 +599,8 @@ function (LookupInSpec $item) {
$this->name,
$id,
$encoded,
LookupInOptions::export($options)
LookupInOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new LookupInResult($response, LookupInOptions::getTranscoder($options));
}
Expand Down Expand Up @@ -630,7 +643,8 @@ function (LookupInSpec $item) {
$this->name,
$id,
$encoded,
LookupInAnyReplicaOptions::export($options)
LookupInAnyReplicaOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new LookupInReplicaResult($response, LookupInAnyReplicaOptions::getTranscoder($options));
}
Expand Down Expand Up @@ -674,7 +688,8 @@ function (LookupInSpec $item) {
$this->name,
$id,
$encoded,
LookupInAllReplicasOptions::export($options)
LookupInAllReplicasOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return array_map(
function (array $response) use ($options) {
Expand Down Expand Up @@ -727,7 +742,8 @@ function (MutateInSpec $item) use ($options) {
$this->name,
$id,
$encoded,
MutateInOptions::export($options)
MutateInOptions::export($options),
$obsHandler->getCoreSpansArray()
);
return new MutateInResult($response);
}
Expand Down
Loading
Loading