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

Create opentracing shim implementation #6

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"license": "Apache-2.0",
"require": {
"php": "^7.4 || ^8.0",
"cloudevents/sdk-php": "^v1.0.1",
"ext-json": "*",
"cloudevents/sdk-php": "^v1.0.1",
"google/protobuf": "^3.3.0",
"grpc/grpc": "^1.30",
"opentracing/opentracing": "^1.0",
"packaged/thrift": "^0.15.0",
"php-http/async-client-implementation": "^1.0",
"php-http/discovery": "^1.14",
Expand Down
39 changes: 39 additions & 0 deletions src/OpenTracingShim/ScopeManagerShim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

class ScopeManagerShim implements \OpenTracing\ScopeManager
{
/**
* Activates an `Span`, so that it is used as a parent when creating new spans.
* The implementation must keep track of the active spans sequence, so
* that previous spans can be resumed after a deactivation.
*
* @param Span $span the {@link Span} that should become the {@link #active()}
* @param bool $finishSpanOnClose whether span should automatically be finished
* when {@link Scope#close()} is called. Its default value is true.
*
* @return Scope instance to control the end of the active period for the {@link Span}. It is a
* programming error to neglect to call {@link Scope#close()} on the returned instance.
*/
public function activate(\OpenTracing\Span $span, bool $finishSpanOnClose = \OpenTracing\ScopeManager::DEFAULT_FINISH_SPAN_ON_CLOSE): \OpenTracing\Scope
{
throw new BadMethodCallException("Not implemented");
}

/**
* Return the currently active {@link Scope} which can be used to access the
* currently active {@link Scope#getSpan()}.
*
* If there is an {@link Scope non-null scope}, its wrapped {@link Span} becomes an implicit parent
* (as {@link References#CHILD_OF} reference) of any
* newly-created {@link Span} at {@link Tracer.SpanBuilder#startActive(boolean)} or {@link SpanBuilder#start()}
* time rather than at {@link Tracer#buildSpan(String)} time.
*
* @return Scope|null
*/
public function getActive(): ?\OpenTracing\Scope
{
throw new BadMethodCallException("Not implemented");
}
}
28 changes: 28 additions & 0 deletions src/OpenTracingShim/ScopeShim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

class ScopeShim implements \OpenTracing\Scope
{
/**
* Mark the end of the active period for the current thread and {@link Scope},
* updating the {@link ScopeManager#active()} in the process.
*
* NOTE: Calling {@link #close} more than once on a single {@link Scope} instance leads to undefined
* behavior.
*
* @return void
*/
public function close(): void
{
throw new BadMethodCallException("Not implemented");
}

/**
* @return Span the {@link Span} that's been scoped by this {@link Scope}
*/
public function getSpan(): \OpenTracing\Span
{
throw new BadMethodCallException("Not implemented");
}
}
49 changes: 49 additions & 0 deletions src/OpenTracingShim/SpanContextShim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

use OpenTelemetry\API\Trace\SpanContext;

class SpanContextShim implements \OpenTracing\SpanContext
{
private SpanContext $otelSpanContext;

public function __construct(SpanContext $otelSpanContext)
{
$this->otelSpanContext = $otelSpanContext;
}

/**
* Returns the value of a baggage item based on its key. If there is no
* value with such key it will return null.
*
* @param string $key
* @return string|null
*/
public function getBaggageItem(string $key): ?string
{
throw new BadMethodCallException("Not implemented");
}

/**
* Creates a new SpanContext out of the existing one and the new key => value pair.
*
* @param string $key
* @param string $value
* @return SpanContext
*/
public function withBaggageItem(string $key, string $value): \OpenTracing\SpanContext
{
throw new BadMethodCallException("Not implemented");
}

public function getIterator(): Traversable
{
throw new BadMethodCallException("Not implemented");
}

public function getSpanContext(): SpanContext
{
return $this->otelSpanContext;
}
}
115 changes: 115 additions & 0 deletions src/OpenTracingShim/SpanShim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

declare(strict_types=1);

class SpanShim implements \OpenTracing\Span
{
/**
* @return string
*/
public function getOperationName(): string
{
throw new BadMethodCallException("Not implemented");
}

/**
* Yields the SpanContext for this Span. Note that the return value of
* Span::getContext() is still valid after a call to Span::finish(), as is
* a call to Span::getContext() after a call to Span::finish().
*
* @return SpanContext
*/
public function getContext(): \OpenTracing\SpanContext
{
throw new BadMethodCallException("Not implemented");
}

/**
* Sets the end timestamp and finalizes Span state.
*
* With the exception of calls to getContext() (which are always allowed),
* finish() must be the last call made to any span instance, and to do
* otherwise leads to undefined behavior but not returning an exception.
*
* As an implementor, make sure you call {@see Tracer::deactivate()}
* otherwise new spans might try to be child of this one.
*
* If the span is already finished, a warning should be logged.
*
* @param float|int|DateTimeInterface|null $finishTime if passing float or int
* it should represent the timestamp (including as many decimal places as you need)
* @return void
*/
public function finish($finishTime = null): void
{
throw new BadMethodCallException("Not implemented");
}

/**
* If the span is already finished, a warning should be logged.
*
* @param string $newOperationName
* @return void
*/
public function overwriteOperationName(string $newOperationName): void
{
throw new BadMethodCallException("Not implemented");
}

/**
* Adds a tag to the span.
*
* If there is a pre-existing tag set for key, it is overwritten.
*
* As an implementor, consider using "standard tags" listed in {@see \OpenTracing\Tags}
*
* If the span is already finished, a warning should be logged.
*
* @param string $key
* @param string|bool|int|float $value
* @return void
*/
public function setTag(string $key, $value): void
{
throw new BadMethodCallException("Not implemented");
}

/**
* Adds a log record to the span in key => value format, key must be a string and tag must be either
* a string, a boolean value, or a numeric type.
*
* If the span is already finished, a warning should be logged.
*
* @param array $fields
* @param int|float|DateTimeInterface $timestamp
* @return void
*/
public function log(array $fields = [], $timestamp = null): void
{
throw new BadMethodCallException("Not implemented");
}

/**
* Adds a baggage item to the SpanContext which is immutable so it is required to use
* SpanContext::withBaggageItem to get a new one.
*
* If the span is already finished, a warning should be logged.
*
* @param string $key
* @param string $value
* @return void
*/
public function addBaggageItem(string $key, string $value): void
{
throw new BadMethodCallException("Not implemented");
}

/**
* @param string $key
* @return string|null returns null when there is not a item under the provided key
*/
public function getBaggageItem(string $key): ?string
{
throw new BadMethodCallException("Not implemented");
}
}
Loading