Skip to content

Commit 46e5fc3

Browse files
committed
Fixing service_name testcase
1 parent 1b07b61 commit 46e5fc3

File tree

7 files changed

+23
-29
lines changed

7 files changed

+23
-29
lines changed

.gitsplit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ splits:
1111
- prefix: "src/Aws"
1212
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-aws.git"
1313
- prefix: "src/Exporter/Instana"
14-
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-instana-exporter.git"
14+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-exporter-instana.git"
1515
- prefix: "src/Symfony"
1616
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-sdk-bundle.git"
1717
- prefix: "src/Instrumentation/CodeIgniter"

src/Exporter/Instana/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/contrib-instana-exporter/releases)
1+
[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/contrib-exporter-instana/releases)
22
[![Issues](https://img.shields.io/badge/issues-pink)](https://www.ibm.com/support/pages/instana-support)
33
[![Source](https://img.shields.io/badge/source-contrib-green)](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Exporter/Instana)
4-
[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php--contrib-blue)](https://github.com/opentelemetry-php/contrib-instana-exporter)
5-
[![Latest Version](http://poser.pugx.org/open-telemetry/opentelemetry-instana-exporter/v/unstable)](https://packagist.org/packages/open-telemetry/opentelemetry-instana-exporter/)
6-
[![Stable](http://poser.pugx.org/open-telemetry/opentelemetry-instana-exporter/v/stable)](https://packagist.org/packages/open-telemetry/opentelemetry-instana-exporter/)
4+
[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php--contrib-blue)](https://github.com/opentelemetry-php/contrib-exporter-instana)
5+
[![Latest Version](http://poser.pugx.org/open-telemetry/opentelemetry-instana-exporter/v/unstable)](https://packagist.org/packages/open-telemetry/opentelemetry-exporter-instana/)
6+
[![Stable](http://poser.pugx.org/open-telemetry/opentelemetry-instana-exporter/v/stable)](https://packagist.org/packages/open-telemetry/opentelemetry-exporter-instana/)
77

88
This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.
99

@@ -26,7 +26,7 @@ curl -s https://getcomposer.org/installer | php
2626
Install via Composer
2727

2828
```bash
29-
composer require instana/contrib-instana-exporter
29+
composer require instana/opentelemetry-exporter-instana
3030
```
3131

3232
## Usage
@@ -44,7 +44,7 @@ INSTANA_AGENT_PORT=42699
4444
The service name that is visible in the Instana UI can be configured with the following environment variables. OpenTelemetry provides `OTEL_SERVICE_NAME` (see documentation [here](https://opentelemetry.io/docs/languages/sdk-configuration/general/#otel_service_name)) as a way to customize this within the SDK. We also provide `INSTANA_SERVICE_NAME` which will be taken as the highest precedence.
4545

4646
```bash
47-
INSTANA_SERVICE_NAME=custom-service-name
47+
export INSTANA_SERVICE_NAME=custom-service-name
4848
```
4949

5050
## Example
@@ -71,6 +71,6 @@ $span->end();
7171
$tracerProvider->shutdown();
7272
```
7373

74-
## Contributions
74+
## Issues
7575

76-
This repo is maintained by IBM Instana and is read-only. Issues and other contributions should be reported as part of standard [Instana product support](https://www.ibm.com/support/pages/instana-support).
76+
This repo is maintained by IBM Instana and is read-only. Issues should be reported as part of standard [Instana product support](https://www.ibm.com/support/pages/instana-support).

src/Exporter/Instana/composer.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
{
2-
"name": "instana/opentelemetry-php-exporter",
2+
"name": "instana/opentelemetry-exporter-instana",
33
"description": "Instana exporter for OpenTelemetry PHP.",
4-
"keywords": [
5-
"opentelemetry",
6-
"otel",
7-
"tracing",
8-
"contrib",
9-
"exporter",
10-
"instana"
11-
],
124
"type": "library",
135
"support": {
146
"issues": "https://www.ibm.com/support/pages/instana-support",

src/Exporter/Instana/src/InstanaTransport.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public function __construct(
5555
}
5656

5757
$this->client = new Client(['base_uri' => $endpoint]);
58-
5958
$this->announce();
6059
}
6160

@@ -233,8 +232,8 @@ private function performAnnounce(): bool
233232
}
234233

235234
/**
236-
* @psalm-suppress FalsableReturnStatement
237-
*/
235+
* @psalm-suppress FalsableReturnStatement
236+
*/
238237
private function getAnnouncementPayload(): string
239238
{
240239
$cmdline_args = file_get_contents('/proc/self/cmdline');

src/Exporter/Instana/src/SpanConverter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class SpanConverter implements SpanConverterInterface
2828
const OTEL_KEY_DROPPED_ATTRIBUTES_COUNT = 'dropped_attributes_count';
2929
const OTEL_KEY_DROPPED_EVENTS_COUNT = 'dropped_events_count';
3030
const OTEL_KEY_DROPPED_LINKS_COUNT = 'dropped_links_count';
31-
3231
private readonly string $defaultServiceName;
3332

3433
public function __construct(
@@ -82,7 +81,10 @@ private function convertSpan(SpanDataInterface $span): array
8281
}
8382

8483
$serviceName = $span->getResource()->getAttributes()->get(ResourceAttributes::SERVICE_NAME) ?? $this->defaultServiceName;
85-
$instanaSpan['data']['service'] = $_SERVER['INSTANA_SERVICE_NAME'] ?? $serviceName;
84+
if (Configuration::has('INSTANA_SERVICE_NAME')) {
85+
$serviceName = Configuration::getString('INSTANA_SERVICE_NAME');
86+
}
87+
$instanaSpan['data']['service'] = $serviceName;
8688

8789
$instanaSpan['data']['sdk']['name'] = $span->getName() ?: 'sdk';
8890
$instanaSpan['data']['sdk']['custom']['tags'] = [];

src/Exporter/Instana/src/SpanExporter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function __construct(
3131
}
3232

3333
/**
34-
* @throws JsonException
35-
*/
34+
* @throws JsonException
35+
*/
3636
protected function serializeTrace(iterable $spans): string
3737
{
3838
return json_encode(

src/Exporter/Instana/tests/Unit/SpanConverterTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function setUp(): void
3131

3232
public function test_should_convert_a_span_to_a_payload_for_instana(): void
3333
{
34+
putenv('INSTANA_SERVICE_NAME=instana/opentelemetry-exporter-instana');
3435
$span = (new SpanDataUtil())
3536
->setName('converter.test')
3637
->setKind(OtelSpanKind::KIND_CLIENT)
@@ -58,7 +59,7 @@ public function test_should_convert_a_span_to_a_payload_for_instana(): void
5859
null,
5960
Attributes::create([]),
6061
))
61-
->addAttribute('service', ['name' => 'instana/opentelemetry-php-exporter', 'version' => 'dev-main'])
62+
->addAttribute('service', ['name' => 'instana/opentelemetry-exporter-instana', 'version' => 'dev-main'])
6263
->addAttribute('net.peer.name', 'authorizationservice.com')
6364
->addAttribute('peer.service', 'AuthService')
6465
->setResource(
@@ -86,7 +87,7 @@ public function test_should_convert_a_span_to_a_payload_for_instana(): void
8687
$this->assertSame(2, $instanaSpan['k']);
8788

8889
$this->assertCount(2, $instanaSpan['data']);
89-
$this->assertSame('instana/opentelemetry-php-exporter', $instanaSpan['data']['service']);
90+
$this->assertSame('instana/opentelemetry-exporter-instana', $instanaSpan['data']['service']);
9091
$this->assertSame($span->getName(), $instanaSpan['data']['sdk']['name']);
9192

9293
$tags = $instanaSpan['data']['sdk']['custom']['tags'];
@@ -97,7 +98,7 @@ public function test_should_convert_a_span_to_a_payload_for_instana(): void
9798
$this->assertSame('test-a', $tags['instance']);
9899

99100
$this->assertCount(3, $tags['attributes']);
100-
$this->assertSame('unknown_service:php', $tags['attributes']['service']['name']);
101+
$this->assertSame('instana/opentelemetry-exporter-instana', $tags['attributes']['service']['name']);
101102
$this->assertSame('dev-main', $tags['attributes']['service']['version']);
102103
$this->assertSame('authorizationservice.com', $tags['attributes']['net.peer.name']);
103104
$this->assertSame('AuthService', $tags['attributes']['peer.service']);
@@ -138,7 +139,7 @@ public function test_should_omit_empty_keys_from_instana_span(): void
138139

139140
$this->assertArrayNotHasKey('p', $instanaSpan);
140141
$this->assertSame('php', $instanaSpan['n']);
141-
$this->assertSame('instana/opentelemetry-php-exporter', $instanaSpan['data']['service']);
142+
$this->assertSame('instana/opentelemetry-exporter-instana', $instanaSpan['data']['service']);
142143
$this->assertSame('test-span-data', $instanaSpan['data']['sdk']['name']);
143144
$this->assertCount(2, $instanaSpan['data']);
144145
}

0 commit comments

Comments
 (0)