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

Only tag args if there are any #141

Merged
merged 4 commits into from Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Agent.php
Expand Up @@ -30,6 +30,7 @@
use Scoutapm\Extension\PotentiallyAvailableExtensionCapabilities;
use Scoutapm\Logger\FilteredLogLevelDecorator;
use Throwable;
use function count;
use function is_string;
use function json_encode;
use function sprintf;
Expand Down Expand Up @@ -213,7 +214,13 @@ private function addSpansFromExtension() : void

foreach ($this->phpExtension->getCalls() as $recordedCall) {
$callSpan = $this->request->startSpan($recordedCall->functionName(), $recordedCall->timeEntered());
$callSpan->tag(Tag::TAG_ARGUMENTS, $recordedCall->filteredArguments());

$arguments = $recordedCall->filteredArguments();

if (count($arguments) > 0) {
$callSpan->tag(Tag::TAG_ARGUMENTS, $arguments);
}

$this->request->stopSpan($recordedCall->timeExited());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Events/Tag/Tag.php
Expand Up @@ -12,7 +12,7 @@
abstract class Tag implements Command
{
public const TAG_STACK_TRACE = 'stack';
public const TAG_ARGUMENTS = 'desc';
public const TAG_ARGUMENTS = 'args';
public const TAG_MEMORY_DELTA = 'memory_delta';
public const TAG_REQUEST_PATH = 'path';

Expand Down
3 changes: 2 additions & 1 deletion src/Extension/RecordedCall.php
Expand Up @@ -84,7 +84,8 @@ public function timeExited() : float

/**
* We should never return the full set of arguments, only specific arguments for specific functions. This is to
* avoid potentially spilling personally identifiable information.
* avoid potentially spilling personally identifiable information. Another reason to only return specific arguments
* is to avoid sending loads of data unnecessarily.
*
* @return mixed[]
*/
Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/AgentTest.php
Expand Up @@ -148,23 +148,23 @@ public function testLoggingIsSent() : void

if (TestHelper::scoutApmExtensionAvailable()) {
$fileGetContentsSpanId = $this->assertUnserializedCommandContainsPayload('StartSpan', ['operation' => 'file_get_contents', 'parent_id' => $controllerSpanId], next($commands), 'span_id');
$this->assertUnserializedCommandContainsPayload('TagSpan', ['span_id' => $fileGetContentsSpanId, 'tag' => 'desc', 'value' => ['url' => __FILE__]], next($commands), null);
$this->assertUnserializedCommandContainsPayload('TagSpan', ['span_id' => $fileGetContentsSpanId, 'tag' => 'args', 'value' => ['url' => __FILE__]], next($commands), null);
$this->assertUnserializedCommandContainsPayload('StopSpan', ['span_id' => $fileGetContentsSpanId], next($commands), null);
}

$fooSpanId = $this->assertUnserializedCommandContainsPayload('StartSpan', ['operation' => 'Test/foo'], next($commands), 'span_id');

if (TestHelper::scoutApmExtensionAvailable()) {
$fileGetContentsSpanId = $this->assertUnserializedCommandContainsPayload('StartSpan', ['operation' => 'file_get_contents', 'parent_id' => $fooSpanId], next($commands), 'span_id');
$this->assertUnserializedCommandContainsPayload('TagSpan', ['span_id' => $fileGetContentsSpanId, 'tag' => 'desc', 'value' => ['url' => __FILE__]], next($commands), null);
$this->assertUnserializedCommandContainsPayload('TagSpan', ['span_id' => $fileGetContentsSpanId, 'tag' => 'args', 'value' => ['url' => __FILE__]], next($commands), null);
$this->assertUnserializedCommandContainsPayload('StopSpan', ['span_id' => $fileGetContentsSpanId], next($commands), null);
}

$barSpanId = $this->assertUnserializedCommandContainsPayload('StartSpan', ['operation' => 'Test/bar'], next($commands), 'span_id');

if (TestHelper::scoutApmExtensionAvailable()) {
$fileGetContentsSpanId = $this->assertUnserializedCommandContainsPayload('StartSpan', ['operation' => 'file_get_contents', 'parent_id' => $barSpanId], next($commands), 'span_id');
$this->assertUnserializedCommandContainsPayload('TagSpan', ['span_id' => $fileGetContentsSpanId, 'tag' => 'desc', 'value' => ['url' => __FILE__]], next($commands), null);
$this->assertUnserializedCommandContainsPayload('TagSpan', ['span_id' => $fileGetContentsSpanId, 'tag' => 'args', 'value' => ['url' => __FILE__]], next($commands), null);
$this->assertUnserializedCommandContainsPayload('StopSpan', ['span_id' => $fileGetContentsSpanId], next($commands), null);
}

Expand All @@ -176,7 +176,7 @@ public function testLoggingIsSent() : void

if (TestHelper::scoutApmExtensionAvailable()) {
$fileGetContentsSpanId = $this->assertUnserializedCommandContainsPayload('StartSpan', ['operation' => 'file_get_contents', 'parent_id' => $controllerSpanId], next($commands), 'span_id');
$this->assertUnserializedCommandContainsPayload('TagSpan', ['span_id' => $fileGetContentsSpanId, 'tag' => 'desc', 'value' => ['url' => __FILE__]], next($commands), null);
$this->assertUnserializedCommandContainsPayload('TagSpan', ['span_id' => $fileGetContentsSpanId, 'tag' => 'args', 'value' => ['url' => __FILE__]], next($commands), null);
$this->assertUnserializedCommandContainsPayload('StopSpan', ['span_id' => $fileGetContentsSpanId], next($commands), null);
}

Expand Down