Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
2e5ee23
Improve instrumentation
Jun 11, 2020
56dbb02
dummy commit to run CI tests on nenad/opencensus
Jul 31, 2020
bd622c3
fix php code style
Jul 31, 2020
6b911e1
fix unit tests
Aug 5, 2020
5bfaf75
limit spans per trace (#2)
Oct 22, 2020
e3be8d7
add span.kind as a tag in PDO, redis extensions (#3)
Nov 26, 2020
f393a0f
checkpoint-1
ShivamYuvraj Jan 25, 2021
2d81ac2
modified removed span method
ShivamYuvraj Jan 26, 2021
1cc8918
added comments
ShivamYuvraj Jan 26, 2021
bdfcbbf
added get span count function
ShivamYuvraj Jan 30, 2021
9e00899
request time bug fix
ShivamYuvraj Jan 30, 2021
a5ed06f
comments
ShivamYuvraj Jan 30, 2021
4197723
Fix extraction from headers
pratt3003 Feb 2, 2021
c409365
Update JaegerPropagator.php
pratt3003 Feb 2, 2021
8b6bd78
Merge pull request #5 from razorpay/fix_extraction
pratt3003 Feb 2, 2021
7d3d509
Update JaegerPropagator.php
pratt3003 Feb 4, 2021
007f190
Merge pull request #6 from razorpay/pratt3003-patch-1
pratt3003 Feb 4, 2021
f1b39d5
made changes in readme
ShivamYuvraj Feb 7, 2021
65557ca
added tests
ShivamYuvraj Feb 8, 2021
731dc8f
test fix
ShivamYuvraj Feb 8, 2021
028ee0e
test fix
ShivamYuvraj Feb 10, 2021
1968b08
Merge pull request #4 from razorpay/bug/memory_bloat_fix
Feb 10, 2021
c544db7
typo fix
ShivamYuvraj Feb 10, 2021
5089946
Merge pull request #7 from razorpay/bg/redis-tracer
Feb 10, 2021
014163b
github action integration
ShivamYuvraj Feb 11, 2021
c86071f
fixed repo name
ShivamYuvraj Feb 11, 2021
0133970
changed run-on in github action
ShivamYuvraj Feb 12, 2021
6094350
updated build image file
ShivamYuvraj Feb 12, 2021
2828d6c
changed docker file
ShivamYuvraj Feb 12, 2021
9352522
changed dokcerfile
ShivamYuvraj Feb 12, 2021
fbfe947
changed dokcerfile
ShivamYuvraj Feb 12, 2021
9a976d0
changed dokcerfile
ShivamYuvraj Feb 12, 2021
f3cb43e
changed dokcerfile
ShivamYuvraj Feb 12, 2021
19c034e
minor change
ShivamYuvraj Feb 12, 2021
875b708
minor change
ShivamYuvraj Feb 12, 2021
77abdb0
minor change
ShivamYuvraj Feb 12, 2021
f4eb3f7
minor change
ShivamYuvraj Feb 12, 2021
d9eff17
minor change
ShivamYuvraj Feb 12, 2021
c5ba5c5
chenged username key
ShivamYuvraj Feb 12, 2021
277cce7
chenged username key
ShivamYuvraj Feb 12, 2021
aeedadc
[ci_integration] Fixes registry.
ace03uec Feb 12, 2021
db7fdaf
chenged username key
ShivamYuvraj Feb 12, 2021
ea73f16
docker changes
ShivamYuvraj Feb 12, 2021
73e71cb
dockerfile new
ShivamYuvraj Feb 12, 2021
67a123c
docker file changes
ShivamYuvraj Feb 15, 2021
e6d7e44
php7.2
ShivamYuvraj Feb 16, 2021
1b9822a
docker changes
ShivamYuvraj Feb 16, 2021
de847ac
minor changes
ShivamYuvraj Feb 16, 2021
0c9ae55
minor change
ShivamYuvraj Feb 17, 2021
a996c51
docker changes
ShivamYuvraj Feb 17, 2021
6bea44b
docker changes
ShivamYuvraj Feb 17, 2021
6f1b922
docker changes
ShivamYuvraj Feb 17, 2021
80d6d9a
docker changes
ShivamYuvraj Feb 17, 2021
9994a45
add standard tags for db and redis suggested by [otel](https://github…
Feb 11, 2021
f9daba4
fix redis and database tags (#10)
Mar 2, 2021
cbc1dc0
merged master
ShivamYuvraj Mar 2, 2021
6f877e8
Merge pull request #8 from razorpay/otel-standard-tags-db-redis
Mar 3, 2021
62b2b3d
Merge branch 'master' of github.com:razorpay/opencensus-php into ci_i…
ShivamYuvraj Mar 3, 2021
7f0317f
updated docker file
ShivamYuvraj Mar 3, 2021
dae70b4
updated docker file
ShivamYuvraj Mar 3, 2021
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
42 changes: 42 additions & 0 deletions .github/workflows/build_images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on: [push]
jobs:
cancel:
runs-on: ubuntu-latest
name: Cancel Previous Runs
if: always()
steps:
- uses: styfle/cancel-workflow-action@d57d93c3a8110b00c3a2c0b64b8516013c9fd4c9
if: github.ref != 'refs/heads/master'
name: cancel old workflows
id: cancel
with:
workflow_id: "build_images.yml"
access_token: ${{ github.token }}
- if: github.ref == 'refs/heads/master'
name: Don't cancel old workflows
id: dont_cancel
run: |
echo "Don't cancel old workflow"
build-web:
name: Extension Build
runs-on: ubuntu-latest
needs: [cancel]
continue-on-error: false
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Login to Dockerhub
uses: docker/login-action@v1
with:
username: ${{ secrets.PUBLIC_DOCKER_USERNAME }}
password: ${{ secrets.PUBLIC_DOCKER_PASSWORD }}
- name: Push To Dockerhub
uses: docker/build-push-action@v1
with:
username: ${{ secrets.PUBLIC_DOCKER_USERNAME }}
password: ${{ secrets.PUBLIC_DOCKER_PASSWORD }}
repository: ${{ github.repository }}
tags: ${{ github.sha }}
dockerfile: Dockerfile.rzp
build_args: GIT_COMMIT_HASH=${{ github.sha }},GIT_TOKEN=${{ secrets.GIT_ACTION_TOKEN }},GIT_USERNAME=rzp

5 changes: 5 additions & 0 deletions Dockerfile.rzp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM razorpay/onggi:php-base

COPY ext /ext

RUN cd /ext && phpize && ./configure --enable-opencensus && make install
28 changes: 28 additions & 0 deletions ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,26 @@ You can retrieve the version of this extension at runtime.
function opencensus_trace_version();
```

```php
/**
* Retrieve the count of collected trace spans, currently in memory
*
* @return int
*/
function opencensus_trace_count();
}
```

```php
/**
* Removes a span from the list.
*
* @param string $key
*
*/
function opencensus_trace_remove_span($key);
```

This library follows [Semantic Versioning](http://semver.org/).

Please note it is currently under active development. Any release versioned
Expand All @@ -342,3 +362,11 @@ See [CONTRIBUTING](../CONTRIBUTING.md) for more information on how to get starte
## License

Apache 2.0 - See [LICENSE](LICENSE) for more information.

## Exporting span once limit is reached to stop memory from bloating

Have added $spanBufferLimit variable in ExtensionTracer.php to control the maximun number
of spans that can be hold in memory at any time, when the limit is reached the tracer itself
export all the closed spans.


6 changes: 6 additions & 0 deletions ext/opencensus.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_opencensus_trace_add_attribute, 0, 0, 2)
ZEND_ARG_ARRAY_INFO(0, options, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_opencensus_trace_remove_span, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_opencensus_trace_add_annotation, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, description, IS_STRING, 0)
ZEND_ARG_ARRAY_INFO(0, options, 0)
Expand Down Expand Up @@ -90,12 +94,14 @@ static zend_function_entry opencensus_functions[] = {
PHP_FE(opencensus_trace_function, arginfo_opencensus_trace_function)
PHP_FE(opencensus_trace_method, arginfo_opencensus_trace_method)
PHP_FE(opencensus_trace_list, NULL)
PHP_FE(opencensus_trace_count, NULL)
PHP_FE(opencensus_trace_begin, arginfo_opencensus_trace_begin)
PHP_FE(opencensus_trace_finish, NULL)
PHP_FE(opencensus_trace_clear, NULL)
PHP_FE(opencensus_trace_set_context, arginfo_opencensus_trace_set_context)
PHP_FE(opencensus_trace_context, NULL)
PHP_FE(opencensus_trace_add_attribute, arginfo_opencensus_trace_add_attribute)
PHP_FE(opencensus_trace_remove_span, arginfo_opencensus_trace_remove_span)
PHP_FE(opencensus_trace_add_annotation, arginfo_opencensus_trace_add_annotation)
PHP_FE(opencensus_trace_add_link, arginfo_opencensus_trace_add_link)
PHP_FE(opencensus_trace_add_message_event, arginfo_opencensus_trace_add_message_event)
Expand Down
40 changes: 38 additions & 2 deletions ext/opencensus_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
#include "standard/php_math.h"
#include "standard/php_rand.h"


/**
* True globals for storing the original zend_execute_ex and
* zend_execute_internal function pointers
*/
static void (*opencensus_original_zend_execute_ex) (zend_execute_data *execute_data);
static void (*opencensus_original_zend_execute_internal) (zend_execute_data *execute_data, zval *return_value);

// Global value to keep the current number of spans in memory
static int SPAN_COUNT = 0;

void opencensus_trace_ginit()
{
/**
Expand Down Expand Up @@ -160,6 +164,27 @@ PHP_FUNCTION(opencensus_trace_add_attribute)
RETURN_FALSE;
}

/**
* Removes a span corresponding to key/span_id from hashtable
* @param string $key
* @return bool
*/
PHP_FUNCTION(opencensus_trace_remove_span)
{
zend_string *k;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &k) == FAILURE) {
RETURN_FALSE;
}

// deleting th span assosciated with the given span_id
// When inserting the sapn, we also pass the destructor function for span span_dtor, which gets called on zend_hash_del
if (zend_hash_del(OPENCENSUS_G(spans), k) != SUCCESS) {
RETURN_FALSE
}

RETURN_TRUE;
}

/**
* Add an annotation to the current trace span
*
Expand Down Expand Up @@ -338,7 +363,6 @@ static zend_string *generate_span_id()
static opencensus_trace_span_t *opencensus_trace_begin(zend_string *name, zend_execute_data *execute_data, zend_string *span_id TSRMLS_DC)
{
opencensus_trace_span_t *span = opencensus_trace_span_alloc();

zend_fetch_debug_backtrace(&span->stackTrace, 1, DEBUG_BACKTRACE_IGNORE_ARGS, 0);

span->start = opencensus_now();
Expand All @@ -357,7 +381,7 @@ static opencensus_trace_span_t *opencensus_trace_begin(zend_string *name, zend_e

/* add the span to the list of spans */
zend_hash_add_ptr(OPENCENSUS_G(spans), span->span_id, span);

SPAN_COUNT++;
return span;
}

Expand Down Expand Up @@ -465,6 +489,7 @@ void span_dtor(zval *zv)
opencensus_trace_span_t *span = Z_PTR_P(zv);
opencensus_trace_span_free(span);
ZVAL_PTR_DTOR(zv);
SPAN_COUNT--;
}

/**
Expand Down Expand Up @@ -553,6 +578,7 @@ PHP_FUNCTION(opencensus_trace_context)
* opencensus_original_zend_execute_ex
*/
void opencensus_trace_execute_ex (zend_execute_data *execute_data TSRMLS_DC) {

zend_string *function_name = opencensus_trace_add_scope_name(
EG(current_execute_data)->func->common.function_name,
EG(current_execute_data)->func->common.scope
Expand Down Expand Up @@ -747,3 +773,13 @@ PHP_FUNCTION(opencensus_trace_list)
} ZEND_HASH_FOREACH_END();
}

/**
* Return the count of trace spans that have been collected for this
* request
*
* @return long
*/
PHP_FUNCTION(opencensus_trace_count)
{
RETURN_LONG(SPAN_COUNT)
}
2 changes: 2 additions & 0 deletions ext/opencensus_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
PHP_FUNCTION(opencensus_trace_function);
PHP_FUNCTION(opencensus_trace_method);
PHP_FUNCTION(opencensus_trace_list);
PHP_FUNCTION(opencensus_trace_count);
PHP_FUNCTION(opencensus_trace_begin);
PHP_FUNCTION(opencensus_trace_finish);
PHP_FUNCTION(opencensus_trace_clear);
PHP_FUNCTION(opencensus_trace_set_context);
PHP_FUNCTION(opencensus_trace_context);
PHP_FUNCTION(opencensus_trace_add_attribute);
PHP_FUNCTION(opencensus_trace_remove_span);
PHP_FUNCTION(opencensus_trace_add_annotation);
PHP_FUNCTION(opencensus_trace_add_link);
PHP_FUNCTION(opencensus_trace_add_message_event);
Expand Down
21 changes: 21 additions & 0 deletions ext/php-helper/DaemonFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ function opencensus_trace_list(): array {
return [];
}

/**
* Retrieve the count of collected trace spans, currently in memory
*
* @return int
*/
function opencensus_trace_count(): int {
return 0;
}


/**
* Clear the list of collected trace spans
*
Expand Down Expand Up @@ -102,6 +112,17 @@ function opencensus_trace_set_context($traceId, $parentSpanId = null): void {
function opencensus_trace_add_attribute($key, $value, $options = []): void {

}

/**
* Removes a span from the list.
*
* @param string $key
*
*/
function opencensus_trace_remove_span($key): bool {

}

/**
* Add an annotation to a span
* @param string $description
Expand Down
13 changes: 13 additions & 0 deletions ext/tests/span_count.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
OpenCensus Trace: Test span count method
--FILE--
<?php

opencensus_trace_begin('root', ['spanId' => 123]);
opencensus_trace_finish();

$count = opencensus_trace_count();
echo "Number of traces: " . $count . "\n";
?>
--EXPECTF--
Number of traces: 1
19 changes: 19 additions & 0 deletions ext/tests/span_remove.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
OpenCensus Trace: Test removing span by id
--FILE--
<?php

opencensus_trace_begin('root', ['spanId' => 123]);
opencensus_trace_finish();

$traces = opencensus_trace_list();
echo "Number of traces: " . count($traces) . "\n";
$span = $traces[0];
$id = $span->spanId();
opencensus_trace_remove_span($id);
$count = opencensus_trace_count();
echo "Number of traces: " . $count . "\n";
?>
--EXPECTF--
Number of traces: 1
Number of traces: 0
42 changes: 39 additions & 3 deletions src/Trace/Integrations/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace OpenCensus\Trace\Integrations;

use OpenCensus\Trace\Span;
use OpenCensus\Trace\Tracer;

/**
* This class handles instrumenting curl requests using the opencensus extension.
Expand Down Expand Up @@ -55,11 +56,46 @@ public static function load()
*/
public static function handleCurlResource($resource)
{
$info = curl_getinfo($resource);
$attrs = self::getSpanAttrsFromCurlInfo($info);

// checks if span limit has reached and if yes exports the closed spans
if (Tracer::$tracer != null) {
Tracer::$tracer->checkSpanLimit();
}

return [
'attributes' => [
'uri' => curl_getinfo($resource, CURLINFO_EFFECTIVE_URL)
],
'attributes' => $attrs,
'kind' => Span::KIND_CLIENT
];
}

private static function getSpanAttrsFromCurlInfo($curlInfo)
{
$tagNameCurlInfoMap = [
'network.client.ip' => 'local_ip',
'network.client.port' => 'local_port',
'network.destination.ip' => 'primary_ip',
'network.destination.port' => 'primary_port',
'network.bytes_read' => 'size_download',
'network.bytes_written' => 'size_upload',
'time_total_in_secs' => 'total_time',
'time_to_connect_in_secs' => 'connect_time',
'time_to_redirect_in_secs' => 'redirect_time',
'time_to_namelookup_in_secs' => 'namelookup_time',
'time_to_pretransfer_in_secs' => 'pretransfer_time',
'time_to_starttransfer_in_secs' => 'starttransfer_time',
'primary_ip' => 'primary_ip',
'uri' => 'url'
];

$attrs = [];

foreach ($tagNameCurlInfoMap as $tagName => $curlInfoName) {
if (isset($curlInfo[$curlInfoName]) && !\trim($curlInfo[$curlInfoName]) !== '') {
$attrs[$tagName] = $curlInfo[$curlInfoName];
}
}
return $attrs;
}
}
Loading