Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ElasticApm/Impl/NoopSpanContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Elastic\Apm\SpanContextDestinationInterface;
use Elastic\Apm\SpanContextHttpInterface;
use Elastic\Apm\SpanContextInterface;
use Elastic\Apm\SpanContextServiceInterface;

/**
* Code in this file is part of implementation internals and thus it is not covered by the backward compatibility.
Expand Down Expand Up @@ -55,4 +56,9 @@ public function http(): SpanContextHttpInterface
{
return NoopSpanContextHttp::singletonInstance();
}

public function service(): SpanContextServiceInterface
{
return NoopSpanContextService::singletonInstance();
}
}
47 changes: 47 additions & 0 deletions src/ElasticApm/Impl/NoopSpanContextService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

declare(strict_types=1);

namespace Elastic\Apm\Impl;

use Elastic\Apm\Impl\Util\NoopObjectTrait;
use Elastic\Apm\SpanContextDbInterface;
use Elastic\Apm\SpanContextDestinationInterface;
use Elastic\Apm\SpanContextHttpInterface;
use Elastic\Apm\SpanContextServiceInterface;
use Elastic\Apm\SpanContextServiceTargetInterface;

/**
* Code in this file is part of implementation internals and thus it is not covered by the backward compatibility.
*
* @internal
*/
final class NoopSpanContextService implements SpanContextServiceInterface
{
use NoopObjectTrait;

/** @inheritDoc */
public function target(): SpanContextServiceTargetInterface
{
return NoopSpanContextServiceTarget::singletonInstance();
}
}
47 changes: 47 additions & 0 deletions src/ElasticApm/Impl/NoopSpanContextServiceTarget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

declare(strict_types=1);

namespace Elastic\Apm\Impl;

use Elastic\Apm\Impl\Util\NoopObjectTrait;
use Elastic\Apm\SpanContextServiceTargetInterface;

/**
* Code in this file is part of implementation internals and thus it is not covered by the backward compatibility.
*
* @internal
*/
final class NoopSpanContextServiceTarget implements SpanContextServiceTargetInterface
{
use NoopObjectTrait;

/** @inheritDoc */
public function setName(?string $name): void
{
}

/** @inheritDoc */
public function setType(?string $type): void
{
}
}
15 changes: 15 additions & 0 deletions src/ElasticApm/Impl/SpanContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Elastic\Apm\SpanContextDbInterface;
use Elastic\Apm\SpanContextDestinationInterface;
use Elastic\Apm\SpanContextHttpInterface;
use Elastic\Apm\SpanContextServiceInterface;
use Elastic\Apm\SpanContextInterface;

/**
Expand All @@ -49,6 +50,9 @@ final class SpanContext extends ExecutionSegmentContext implements SpanContextIn
/** @var SpanContextHttp|null */
private $http = null;

/** @var SpanContextService|null */
private $service = null;

public function __construct(Span $owner, SpanContextData $data)
{
parent::__construct($owner, $data);
Expand Down Expand Up @@ -89,6 +93,17 @@ public function http(): SpanContextHttpInterface
return $this->http;
}

/** @inheritDoc */
public function service(): SpanContextServiceInterface
{
if ($this->service === null) {
$this->data->service = new SpanContextServiceData();
$this->service = new SpanContextService($this->owner, $this->data->service);
}

return $this->service;
}

/**
* @return string[]
*/
Expand Down
15 changes: 14 additions & 1 deletion src/ElasticApm/Impl/SpanContextData.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,25 @@ final class SpanContextData extends ExecutionSegmentContextData
*/
public $http = null;

/**
* @var ?SpanContextServiceData
*
* Service related information can be sent per event.
* Provided information will override the more generic information from metadata,
* non provided fields will be set according to the metadata information.
*
* @link https://github.com/elastic/apm-server/blob/v7.6.0/docs/spec/spans/span.json#L134
*/
public $service = null;

/** @inheritDoc */
public function prepareForSerialization(): bool
{
return parent::prepareForSerialization()
|| SerializationUtil::prepareForSerialization(/* ref */ $this->db)
|| SerializationUtil::prepareForSerialization(/* ref */ $this->destination)
|| SerializationUtil::prepareForSerialization(/* ref */ $this->http);
|| SerializationUtil::prepareForSerialization(/* ref */ $this->http)
|| SerializationUtil::prepareForSerialization(/* ref */ $this->service);
}

/** @inheritDoc */
Expand All @@ -80,6 +92,7 @@ public function jsonSerialize()
SerializationUtil::addNameValueIfNotNull('db', $this->db, /* ref */ $result);
SerializationUtil::addNameValueIfNotNull('destination', $this->destination, /* ref */ $result);
SerializationUtil::addNameValueIfNotNull('http', $this->http, /* ref */ $result);
SerializationUtil::addNameValueIfNotNull('service', $this->service, /* ref */ $result);

return SerializationUtil::postProcessResult($result);
}
Expand Down
59 changes: 59 additions & 0 deletions src/ElasticApm/Impl/SpanContextService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

declare(strict_types=1);

namespace Elastic\Apm\Impl;

use Elastic\Apm\SpanContextServiceInterface;
use Elastic\Apm\SpanContextServiceTargetInterface;

/**
* Code in this file is part of implementation internals and thus it is not covered by the backward compatibility.
*
* @internal
*
* @extends ContextDataWrapper<Span>
*/
final class SpanContextService extends ContextDataWrapper implements SpanContextServiceInterface
{
/** @var SpanContextServiceData */
private $data;

/** @var ?SpanContextServiceTarget */
private $target = null;

public function __construct(Span $owner, SpanContextServiceData $data)
{
parent::__construct($owner);
$this->data = $data;
}

public function target(): SpanContextServiceTargetInterface
{
if ($this->target === null) {
$this->data->target = new SpanContextServiceTargetData();
$this->target = new SpanContextServiceTarget($this->owner, $this->data->target);
}

return $this->target;
}
}
67 changes: 67 additions & 0 deletions src/ElasticApm/Impl/SpanContextServiceData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

declare(strict_types=1);

namespace Elastic\Apm\Impl;

use Elastic\Apm\Impl\BackendComm\SerializationUtil;
use Elastic\Apm\Impl\Log\LoggableInterface;
use Elastic\Apm\Impl\Log\LoggableTrait;

/**
* An object containing contextual data about the destination for spans
*
* @link https://github.com/elastic/apm-server/blob/7.6/docs/spec/spans/span.json#L44
*
* Code in this file is part of implementation internals and thus it is not covered by the backward compatibility.
*
* @internal
*/
final class SpanContextServiceData implements OptionalSerializableDataInterface, LoggableInterface
{
use LoggableTrait;

/**
* @var ?SpanContextServiceTargetData
*
* Target holds information about the outgoing service in case of an outgoing event
*
* @link https://github.com/elastic/apm-server/blob/v8.3.0/docs/spec/v2/span.json#L519
*/
public $target = null;

/** @inheritDoc */
public function prepareForSerialization(): bool
{
return SerializationUtil::prepareForSerialization(/* ref */ $this->target);
}

/** @inheritDoc */
public function jsonSerialize()
{
$result = [];

SerializationUtil::addNameValueIfNotNull('target', $this->target, /* ref */ $result);

return SerializationUtil::postProcessResult($result);
}
}
65 changes: 65 additions & 0 deletions src/ElasticApm/Impl/SpanContextServiceTarget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

declare(strict_types=1);

namespace Elastic\Apm\Impl;

use Elastic\Apm\SpanContextServiceTargetInterface;

/**
* Code in this file is part of implementation internals and thus it is not covered by the backward compatibility.
*
* @internal
*
* @extends ContextDataWrapper<Span>
*/
final class SpanContextServiceTarget extends ContextDataWrapper implements SpanContextServiceTargetInterface
{
/** @var SpanContextServiceTargetData */
private $data;

public function __construct(Span $owner, SpanContextServiceTargetData $data)
{
parent::__construct($owner);
$this->data = $data;
}

/** @inheritDoc */
public function setName(?string $name): void
{
if ($this->beforeMutating()) {
return;
}

$this->data->name = Tracer::limitNullableKeywordString($name);
}

/** @inheritDoc */
public function setType(?string $type): void
{
if ($this->beforeMutating()) {
return;
}

$this->data->type = Tracer::limitNullableKeywordString($type);
}
}
Loading