Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make tracing object fluent #1381

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 7 additions & 3 deletions src/Tracing/DynamicSamplingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ private function __construct()
* @param string $key the list member key
* @param string $value the list member value
*/
public function set(string $key, string $value): void
public function set(string $key, string $value): self
{
if ($this->isFrozen) {
return;
return $this;
}

$this->entries[$key] = $value;

return $this;
}

/**
Expand All @@ -73,9 +75,11 @@ public function get(string $key, ?string $default = null): ?string
/**
* Mark the dsc as frozen.
*/
public function freeze(): void
public function freeze(): self
{
$this->isFrozen = true;

return $this;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Tracing/SamplingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,23 @@ public function getParentSampled(): ?bool
/**
* Sets the sampling decision from the parent transaction, if any.
*/
public function setParentSampled(?bool $parentSampled): void
public function setParentSampled(?bool $parentSampled): self
{
$this->parentSampled = $parentSampled;

return $this;
}

/**
* Sets additional data that will be provided as a second argument to {@link \Sentry\startTransaction()}.
*
* @param array<string, mixed>|null $additionalContext
*/
public function setAdditionalContext(?array $additionalContext): void
public function setAdditionalContext(?array $additionalContext): self
{
$this->additionalContext = $additionalContext;

return $this;
}

/**
Expand Down
44 changes: 33 additions & 11 deletions src/Tracing/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ public function __construct(?SpanContext $context = null)
*
* @param SpanId $spanId The ID
*/
public function setSpanId(SpanId $spanId): void
public function setSpanId(SpanId $spanId): self
{
$this->spanId = $spanId;

return $this;
}

/**
Expand All @@ -129,9 +131,11 @@ public function getTraceId(): TraceId
*
* @param TraceId $traceId The ID
*/
public function setTraceId(TraceId $traceId): void
public function setTraceId(TraceId $traceId): self
{
$this->traceId = $traceId;

return $this;
}

/**
Expand All @@ -147,9 +151,11 @@ public function getParentSpanId(): ?SpanId
*
* @param SpanId|null $parentSpanId The ID
*/
public function setParentSpanId(?SpanId $parentSpanId): void
public function setParentSpanId(?SpanId $parentSpanId): self
{
$this->parentSpanId = $parentSpanId;

return $this;
}

/**
Expand All @@ -165,9 +171,11 @@ public function getStartTimestamp(): float
*
* @param float $startTimestamp The timestamp
*/
public function setStartTimestamp(float $startTimestamp): void
public function setStartTimestamp(float $startTimestamp): self
{
$this->startTimestamp = $startTimestamp;

return $this;
}

/**
Expand All @@ -193,9 +201,11 @@ public function getDescription(): ?string
*
* @param string|null $description The description
*/
public function setDescription(?string $description): void
public function setDescription(?string $description): self
{
$this->description = $description;

return $this;
}

/**
Expand All @@ -211,9 +221,11 @@ public function getOp(): ?string
*
* @param string|null $op The short code
*/
public function setOp(?string $op): void
public function setOp(?string $op): self
{
$this->op = $op;

return $this;
}

/**
Expand All @@ -229,17 +241,19 @@ public function getStatus(): ?SpanStatus
*
* @param SpanStatus|null $status The status
*/
public function setStatus(?SpanStatus $status): void
public function setStatus(?SpanStatus $status): self
{
$this->status = $status;

return $this;
}

/**
* Sets the HTTP status code and the status of the span/transaction.
*
* @param int $statusCode The HTTP status code
*/
public function setHttpStatus(int $statusCode): void
public function setHttpStatus(int $statusCode): self
{
$this->tags['http.status_code'] = (string) $statusCode;

Expand All @@ -248,6 +262,8 @@ public function setHttpStatus(int $statusCode): void
if ($status !== SpanStatus::unknownError()) {
$this->status = $status;
}

return $this;
}

/**
Expand All @@ -265,9 +281,11 @@ public function getTags(): array
*
* @param array<string, string> $tags The tags
*/
public function setTags(array $tags): void
public function setTags(array $tags): self
{
$this->tags = array_merge($this->tags, $tags);

return $this;
}

/**
Expand All @@ -291,9 +309,11 @@ public function getSampled(): ?bool
*
* @param bool $sampled Whether to sample or not this span
*/
public function setSampled(?bool $sampled): void
public function setSampled(?bool $sampled): self
{
$this->sampled = $sampled;

return $this;
}

/**
Expand All @@ -312,9 +332,11 @@ public function getData(): array
*
* @param array<string, mixed> $data The data
*/
public function setData(array $data): void
public function setData(array $data): self
{
$this->data = array_merge($this->data, $data);

return $this;
}

/**
Expand Down
44 changes: 33 additions & 11 deletions src/Tracing/SpanContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,69 +71,83 @@ public function getDescription(): ?string
return $this->description;
}

public function setDescription(?string $description): void
public function setDescription(?string $description): self
{
$this->description = $description;

return $this;
}

public function getOp(): ?string
{
return $this->op;
}

public function setOp(?string $op): void
public function setOp(?string $op): self
{
$this->op = $op;

return $this;
}

public function getStatus(): ?SpanStatus
{
return $this->status;
}

public function setStatus(?SpanStatus $status): void
public function setStatus(?SpanStatus $status): self
{
$this->status = $status;

return $this;
}

public function getParentSpanId(): ?SpanId
{
return $this->parentSpanId;
}

public function setParentSpanId(?SpanId $parentSpanId): void
public function setParentSpanId(?SpanId $parentSpanId): self
{
$this->parentSpanId = $parentSpanId;

return $this;
}

public function getSampled(): ?bool
{
return $this->sampled;
}

public function setSampled(?bool $sampled): void
public function setSampled(?bool $sampled): self
{
$this->sampled = $sampled;

return $this;
}

public function getSpanId(): ?SpanId
{
return $this->spanId;
}

public function setSpanId(?SpanId $spanId): void
public function setSpanId(?SpanId $spanId): self
{
$this->spanId = $spanId;

return $this;
}

public function getTraceId(): ?TraceId
{
return $this->traceId;
}

public function setTraceId(?TraceId $traceId): void
public function setTraceId(?TraceId $traceId): self
{
$this->traceId = $traceId;

return $this;
}

/**
Expand All @@ -147,9 +161,11 @@ public function getTags(): array
/**
* @param array<string, string> $tags
*/
public function setTags(array $tags): void
public function setTags(array $tags): self
{
$this->tags = $tags;

return $this;
}

/**
Expand All @@ -163,29 +179,35 @@ public function getData(): array
/**
* @param array<string, mixed> $data
*/
public function setData(array $data): void
public function setData(array $data): self
{
$this->data = $data;

return $this;
}

public function getStartTimestamp(): ?float
{
return $this->startTimestamp;
}

public function setStartTimestamp(?float $startTimestamp): void
public function setStartTimestamp(?float $startTimestamp): self
{
$this->startTimestamp = $startTimestamp;

return $this;
}

public function getEndTimestamp(): ?float
{
return $this->endTimestamp;
}

public function setEndTimestamp(?float $endTimestamp): void
public function setEndTimestamp(?float $endTimestamp): self
{
$this->endTimestamp = $endTimestamp;

return $this;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Tracing/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ public function getName(): string
*
* @param string $name The name
*/
public function setName(string $name): void
public function setName(string $name): self
{
$this->name = $name;

return $this;
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/Tracing/TransactionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ public function getName(): string
*
* @param string $name The name
*/
public function setName(string $name): void
public function setName(string $name): self
{
$this->name = $name;

return $this;
}

/**
Expand All @@ -73,9 +75,11 @@ public function getParentSampled(): ?bool
*
* @param bool|null $parentSampled The decision
*/
public function setParentSampled(?bool $parentSampled): void
public function setParentSampled(?bool $parentSampled): self
{
$this->parentSampled = $parentSampled;

return $this;
}

/**
Expand All @@ -91,9 +95,11 @@ public function getMetadata(): TransactionMetadata
*
* @param TransactionMetadata $metadata The transaction metadata
*/
public function setMetadata(TransactionMetadata $metadata): void
public function setMetadata(TransactionMetadata $metadata): self
{
$this->metadata = $metadata;

return $this;
}

/**
Expand Down
Loading