summaryrefslogtreecommitdiff
path: root/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Scope.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Scope.php')
-rw-r--r--vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Scope.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Scope.php b/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Scope.php
new file mode 100644
index 000000000..86511bae0
--- /dev/null
+++ b/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Scope.php
@@ -0,0 +1,71 @@
+<?php
+
+namespace Jaeger;
+
+use OpenTracing\Scope as OTScope;
+use OpenTracing\Span as OTSpan;
+
+/**
+ * {@inheritdoc}
+ */
+class Scope implements OTScope
+{
+ /**
+ * @var ScopeManager
+ */
+ private $scopeManager;
+
+ /**
+ * @var OTSpan
+ */
+ private $wrapped;
+
+ /**
+ * @var OTScope|null
+ */
+ private $toRestore;
+
+ /**
+ * @var bool
+ */
+ private $finishSpanOnClose;
+
+ /**
+ * Scope constructor.
+ * @param ScopeManager $scopeManager
+ * @param OTSpan $wrapped
+ * @param bool $finishSpanOnClose
+ */
+ public function __construct(ScopeManager $scopeManager, OTSpan $wrapped, bool $finishSpanOnClose)
+ {
+ $this->scopeManager = $scopeManager;
+ $this->wrapped = $wrapped;
+ $this->finishSpanOnClose = $finishSpanOnClose;
+ $this->toRestore = $scopeManager->getActive();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function close(): void
+ {
+ if ($this->scopeManager->getActive() !== $this) {
+ // This shouldn't happen if users call methods in expected order
+ return;
+ }
+
+ if ($this->finishSpanOnClose) {
+ $this->wrapped->finish();
+ }
+
+ $this->scopeManager->setActive($this->toRestore);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getSpan(): OTSpan
+ {
+ return $this->wrapped;
+ }
+}