Skip to content
Merged
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
7 changes: 4 additions & 3 deletions src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ protected function handleProduceMessage(ProceedingJoinPoint $proceedingJoinPoint
}

$span = $this->startSpan(
'queue.publish',
sprintf('%s::%s()', $proceedingJoinPoint->className, $proceedingJoinPoint->methodName)
op: 'queue.publish',
description: sprintf('%s::%s()', $proceedingJoinPoint->className, $proceedingJoinPoint->methodName),
origin: 'auto.amqp'
);

if (! $span) {
Expand Down Expand Up @@ -110,6 +111,6 @@ protected function handleProduceMessage(ProceedingJoinPoint $proceedingJoinPoint
$this->properties['application_headers']->set(Constants::TRACE_CARRIER, $carrier->toJson());
})->call($producerMessage);

return tap($proceedingJoinPoint->process(), fn () => $span->setOrigin('auto.amqp')->finish());
return tap($proceedingJoinPoint->process(), fn () => $span->finish());
}
}
8 changes: 5 additions & 3 deletions src/sentry/src/Tracing/Aspect/AsyncQueueJobMessageAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ public function handleGet(ProceedingJoinPoint $proceedingJoinPoint)

public function handlePush(ProceedingJoinPoint $proceedingJoinPoint)
{
/** @var \Hyperf\AsyncQueue\JobInterface $job */
$job = $proceedingJoinPoint->arguments['keys']['job'] ?? null;
$span = $this->startSpan(
'queue.publish',
$job::class
op: 'queue.publish',
description: $job::class,
origin: 'auto.queue'
);

if (! $span) {
Expand Down Expand Up @@ -109,7 +111,7 @@ public function handlePush(ProceedingJoinPoint $proceedingJoinPoint)

return $proceedingJoinPoint->process();
} finally {
$span->setOrigin('auto.queue')->finish();
$span->finish();
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/sentry/src/Tracing/Aspect/CacheAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
$span = $this->startSpan(
op: $op,
description: implode(', ', $keys),
origin: 'auto.cache',
asParent: true
)->setData([
)?->setData([
'cache.key' => $keys,
'cache.ttl' => $arguments['ttl'] ?? null,
'item_size' => match (true) {
Expand All @@ -95,7 +96,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
],
default => [],
};
$span->setOrigin('auto.cache')->setData($data)->finish();
$span?->setData($data)->finish();
});
} finally {
SentrySdk::getCurrentHub()->setSpan($parent);
Expand Down
27 changes: 15 additions & 12 deletions src/sentry/src/Tracing/Aspect/CoordinatorAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,29 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
];

$span = $this->startSpan(
sprintf('%s.%s', strtolower(class_basename($proceedingJoinPoint->className)), $proceedingJoinPoint->methodName),
sprintf('%s::%s(%s)', $proceedingJoinPoint->className, $proceedingJoinPoint->methodName, $timeout),
);
op: sprintf('%s.%s', strtolower(class_basename($proceedingJoinPoint->className)), $proceedingJoinPoint->methodName),
description: sprintf('%s::%s(%s)', $proceedingJoinPoint->className, $proceedingJoinPoint->methodName, $timeout),
origin: 'auto.coordinator',
)?->setData($data);

try {
return $proceedingJoinPoint->process();
} catch (Throwable $exception) {
$span?->setStatus(SpanStatus::internalError());
$span?->setTags([
'error' => true,
'exception.class' => $exception::class,
'exception.message' => $exception->getMessage(),
'exception.code' => $exception->getCode(),
]);
$span?->setStatus(SpanStatus::internalError())
->setTags([
'error' => true,
'exception.class' => $exception::class,
'exception.message' => $exception->getMessage(),
'exception.code' => $exception->getCode(),
]);
if ($this->switcher->isTracingExtraTagEnable('exception.stack_trace')) {
$data['exception.stack_trace'] = (string) $exception;
$span?->setData([
'exception.stack_trace' => (string) $exception,
]);
}
throw $exception;
} finally {
$span?->setOrigin('auto.coordinator')->setData($data)->finish(microtime(true));
$span?->finish(microtime(true));
}
}
}
39 changes: 22 additions & 17 deletions src/sentry/src/Tracing/Aspect/CoroutineAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
}

$callable = $proceedingJoinPoint->arguments['keys']['callable'];
$parent = $this->startSpan('coroutine.create', $callingOnFunction);
$parent = $this->startSpan(
op: 'coroutine.create',
description: $callingOnFunction,
origin: 'auto.coroutine',
)?->setOrigin('auto.coroutine');

if (! $parent) {
return $proceedingJoinPoint->process();
Expand All @@ -62,42 +66,43 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)

$proceedingJoinPoint->arguments['keys']['callable'] = function () use ($callable, $parent, $callingOnFunction) {
$transaction = $this->startCoroutineTransaction(
$parent,
parent: $parent,
name: 'coroutine',
op: 'coroutine.execute',
description: $callingOnFunction,
);
origin: 'auto.coroutine',
)->setData([
'coroutine.id' => Co::id(),
]);

defer(function () use ($transaction) {
SentrySdk::getCurrentHub()->setSpan($transaction);
$transaction->finish();
});

$data = [
'coroutine.id' => Co::id(),
];

try {
$callable();
} catch (Throwable $exception) {
$transaction->setStatus(SpanStatus::internalError());
$transaction->setTags([
'error' => true,
'exception.class' => $exception::class,
'exception.message' => $exception->getMessage(),
'exception.code' => $exception->getCode(),
]);
$transaction->setStatus(SpanStatus::internalError())
->setTags([
'error' => true,
'exception.class' => $exception::class,
'exception.message' => $exception->getMessage(),
'exception.code' => $exception->getCode(),
]);
if ($this->switcher->isTracingExtraTagEnable('exception.stack_trace')) {
$data['exception.stack_trace'] = (string) $exception;
$transaction->setData([
'exception.stack_trace' => (string) $exception,
]);
}

throw $exception;
} finally {
$transaction->setOrigin('auto.coroutine')->setData($data);
// ...
}
};

$parent->setOrigin('auto.coroutine')->finish();
$parent->finish();

return $proceedingJoinPoint->process();
}
Expand Down
37 changes: 21 additions & 16 deletions src/sentry/src/Tracing/Aspect/DbAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
// $operation ? $operation . ' ' : '',
// implode('.', array_filter([$database, $table]))
// );
$op = 'db.sql.query';
$description = $sql;

// Already check in the previous context
/** @var \Sentry\Tracing\Span $span */
$span = $this->startSpan($op, $description);
$span = $this->startSpan(
op: 'db.sql.query',
description: $sql,
origin: 'auto.db',
);

$data = [
'coroutine.id' => Coroutine::id(),
Expand All @@ -103,26 +102,32 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
$data['db.parameter.' . $key] = $value;
}

$span?->setData($data);

try {
$result = $proceedingJoinPoint->process();
if ($this->switcher->isTracingExtraTagEnable('db.result')) {
$data['db.result'] = json_encode($result, JSON_UNESCAPED_UNICODE);
$span?->setData([
'db.result' => json_encode($result, JSON_UNESCAPED_UNICODE),
]);
}
} catch (Throwable $exception) {
$span->setStatus(SpanStatus::internalError());
$span->setTags([
'error' => true,
'exception.class' => $exception::class,
'exception.message' => $exception->getMessage(),
'exception.code' => $exception->getCode(),
]);
$span?->setStatus(SpanStatus::internalError())
->setTags([
'error' => true,
'exception.class' => $exception::class,
'exception.message' => $exception->getMessage(),
'exception.code' => $exception->getCode(),
]);
if ($this->switcher->isTracingExtraTagEnable('exception.stack_trace')) {
$data['exception.stack_trace'] = (string) $exception;
$span?->setData([
'exception.stack_trace' => (string) $exception,
]);
}

throw $exception;
} finally {
$span->setOrigin('auto.db')->setData($data)->finish();
$span?->finish();
}

return $result;
Expand Down
33 changes: 20 additions & 13 deletions src/sentry/src/Tracing/Aspect/ElasticsearchAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
return $proceedingJoinPoint->process();
}

// TODO 规则: opeate dbName.tableName
// TODO 规则: operate dbName.tableName
$span = $this->startSpan(
'db.elasticserach',
sprintf('%s::%s()', $proceedingJoinPoint->className, $proceedingJoinPoint->methodName),
op: 'db.elasticsearch',
description: sprintf('%s::%s()', $proceedingJoinPoint->className, $proceedingJoinPoint->methodName),
origin: 'auto.elasticsearch',
);

if (! $span) {
Expand All @@ -83,26 +84,32 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
'arguments' => json_encode($proceedingJoinPoint->arguments['keys'], JSON_UNESCAPED_UNICODE),
];

$span->setData($data);

try {
$result = $proceedingJoinPoint->process();
if ($this->switcher->isTracingExtraTagEnable('elasticsearch.result')) {
$data['elasticsearch.result'] = json_encode($result, JSON_UNESCAPED_UNICODE);
$span->setData([
'elasticsearch.result' => json_encode($result, JSON_UNESCAPED_UNICODE),
]);
}
} catch (Throwable $exception) {
$span->setStatus(SpanStatus::internalError());
$span->setTags([
'error' => true,
'exception.class' => $exception::class,
'exception.message' => $exception->getMessage(),
'exception.code' => $exception->getCode(),
]);
$span->setStatus(SpanStatus::internalError())
->setTags([
'error' => true,
'exception.class' => $exception::class,
'exception.message' => $exception->getMessage(),
'exception.code' => $exception->getCode(),
]);
if ($this->switcher->isTracingExtraTagEnable('exception.stack_trace')) {
$data['exception.stack_trace'] = (string) $exception;
$span->setData([
'exception.stack_trace' => (string) $exception,
]);
}

throw $exception;
} finally {
$span->setOrigin('auto.elasticsearch')->setData($data)->finish();
$span->finish();
}

return $result;
Expand Down
27 changes: 17 additions & 10 deletions src/sentry/src/Tracing/Aspect/GrpcAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,30 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
];
$proceedingJoinPoint->arguments['keys']['options'] = $options;

$span = $this->startSpan('grpc.client', $method);
$span = $this->startSpan(
op: 'grpc.client',
description: $method,
origin: 'auto.grpc',
)?->setData($data);

try {
$result = $proceedingJoinPoint->process();

if (! $span) {
return $result;
}

[$message, $code, $response] = $result;

if ($response instanceof Http2Response) {
$data += [
$span->setData([
'response.status' => $code,
'response.reason' => $message,
'response.headers' => $response->headers,
];
if ($this->switcher->isTracingExtraTagEnable('response.body')) {
$data['response.body'] = $response->data;
}
]);
$this->switcher->isTracingExtraTagEnable('response.body') && $span->setData([
'response.body' => $response->data,
]);
}
} catch (Throwable $exception) {
$span?->setStatus(SpanStatus::internalError())
Expand All @@ -83,14 +89,15 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
'exception.message' => $exception->getMessage(),
'exception.code' => $exception->getCode(),
]);
if ($this->switcher->isTracingExtraTagEnable('exception.stack_trace')) {
$data['exception.stack_trace'] = (string) $exception;
}
$this->switcher->isTracingExtraTagEnable('exception.stack_trace') && $span?->setData([
'exception.stack_trace' => (string) $exception,
]);

throw $exception;
} finally {
$span?->setOrigin('auto.grpc')->setData($data)->finish();
$span?->finish();
}

return $result;
}
}
18 changes: 11 additions & 7 deletions src/sentry/src/Tracing/Aspect/GuzzleHttpClientAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
}

// Inject trace context && Start span
$span = $this->startSpan('http.client', $request->getMethod() . ' ' . (string) $request->getUri());
$span = $this->startSpan(
op: 'http.client',
description: $request->getMethod() . ' ' . (string) $request->getUri(),
origin: 'auto.http.client',
);
$options['headers'] = array_replace($options['headers'] ?? [], [
'sentry-trace' => $span->toTraceparent(),
'baggage' => $span->toBaggage(),
Expand Down Expand Up @@ -122,11 +126,11 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
}

if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) {
$span->setStatus(SpanStatus::internalError());
$span->setTags([
'error' => true,
'response.reason' => $response->getReasonPhrase(),
]);
$span->setStatus(SpanStatus::internalError())
->setTags([
'error' => true,
'response.reason' => $response->getReasonPhrase(),
]);
}
}

Expand All @@ -144,7 +148,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
}
}

$span->setOrigin('auto.http.client')->setData($data)->finish();
$span->setData($data)->finish();

if (is_callable($onStats)) {
($onStats)($stats);
Expand Down
Loading