Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit ac567d4

Browse files
authored
Rename RequestTracer->Tracer, Label->Attribute (#67)
* Rename RequestTracer->Tracer * label->attribute * Fix extension README * Fix test from mismerge
1 parent 3c9ed98 commit ac567d4

72 files changed

Lines changed: 371 additions & 370 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ext/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[OpenCensus](https://opencensus.io/) is a free, open-source distributed tracing
44
implementation based on the [Dapper Paper](https://research.google.com/pubs/pub36356.html).
55
This extension allows you to "watch" class method and function calls in order to
6-
automatically collect nested spans (labelled timing data).
6+
automatically collect nested spans (timing data).
77

88
This library can optionally work in conjunction with the PHP library
99
[opencensus/opencensus](https://packagist.org/packages/opencensus/opencensus) in order
@@ -103,7 +103,7 @@ If an array is provided, it should be an associative array with the following op
103103
* `name` - string - the name of the span to create. **Defaults to** the full method name (i.e. `Foobar::__construct`).
104104
* `startTime` - float - the start time of the span. **Defaults to** the time that the method was invoked.
105105
* `endTime` - float - the end time of the span. **Defaults to** the time that the method invocation completed.
106-
* `labels` - array - an associative array of string => string tags for this span.
106+
* `attributes` - array - an associative array of string => string tags for this span.
107107

108108
If a callback is provided, it will be passed the instance of the class (scope) and a copy of each parameter
109109
provided to the watched method. The callback should return an array with the above options. If the callback does
@@ -113,15 +113,15 @@ not return an array, an `E_USER_WARNING` error is thrown.
113113
// Example: supply a static array of span options as the handler
114114
opencensus_trace_method('Foobar', '__construct', [
115115
'name' => 'Foobar::__construct',
116-
'labels' => [
116+
'attributes' => [
117117
'foo' => 'bar'
118118
]
119119
]);
120120

121121
// Example: supply a closure
122122
opencensus_trace_method('Foobar', '__construct', function ($scope, $constructArg1, $constructArg2) {
123123
return [
124-
'labels' => [
124+
'attributes' => [
125125
'arg1' => $constructArg1
126126
]
127127
];
@@ -131,7 +131,7 @@ opencensus_trace_method('Foobar', '__construct', function ($scope, $constructArg
131131
function my_callback($scope, $constructArg1, $constructArg2)
132132
{
133133
return [
134-
'labels' => [
134+
'attributes' => [
135135
'arg1' => $constructArg1
136136
]
137137
];
@@ -164,7 +164,7 @@ not object scope available.
164164
opencensus_trace_function('var_dump', function ($value) {
165165
return [
166166
'name' => 'Foobar::__construct',
167-
'labels' => [
167+
'attributes' => [
168168
'value' => $value
169169
]
170170
];
@@ -244,24 +244,24 @@ You may also set the initial trace context. Note that doing this after spans hav
244244
function opencensus_trace_set_context($traceId, $parentSpanId = null);
245245
```
246246

247-
### Add labels to spans
247+
### Add attributes to spans
248248

249249
```php
250250
/**
251-
* Add a label to the current span
251+
* Add a attribute to the current span
252252
*
253253
* @param string $key
254254
* @param string $value
255255
*/
256-
function opencensus_trace_add_label($key, $value);
256+
function opencensus_trace_add_attribute($key, $value);
257257

258258
/**
259-
* Add a label to the root current span
259+
* Add a attribute to the root current span
260260
*
261261
* @param string $key
262262
* @param string $value
263263
*/
264-
function opencensus_trace_add_root_label($key, $value);
264+
function opencensus_trace_add_root_attribute($key, $value);
265265
```
266266

267267
## Versioning

ext/opencensus_trace.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_opencensus_trace_set_context, 0, 0, 1)
6363
ZEND_ARG_TYPE_INFO(0, parentSpanId, IS_STRING, 1)
6464
ZEND_END_ARG_INFO()
6565

66-
ZEND_BEGIN_ARG_INFO_EX(arginfo_opencensus_trace_add_label, 0, 0, 2)
66+
ZEND_BEGIN_ARG_INFO_EX(arginfo_opencensus_trace_add_attribute, 0, 0, 2)
6767
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
6868
ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
6969
ZEND_END_ARG_INFO()
@@ -79,8 +79,8 @@ static zend_function_entry opencensus_functions[] = {
7979
PHP_FE(opencensus_trace_clear, NULL)
8080
PHP_FE(opencensus_trace_set_context, arginfo_opencensus_trace_set_context)
8181
PHP_FE(opencensus_trace_context, NULL)
82-
PHP_FE(opencensus_trace_add_label, arginfo_opencensus_trace_add_label)
83-
PHP_FE(opencensus_trace_add_root_label, arginfo_opencensus_trace_add_label)
82+
PHP_FE(opencensus_trace_add_attribute, arginfo_opencensus_trace_add_attribute)
83+
PHP_FE(opencensus_trace_add_root_attribute, arginfo_opencensus_trace_add_attribute)
8484
PHP_FE_END
8585
};
8686

@@ -120,13 +120,13 @@ PHP_FUNCTION(opencensus_version)
120120
}
121121

122122
/**
123-
* Add a label to the current trace span
123+
* Add a attribute to the current trace span
124124
*
125125
* @param string $key
126126
* @param string $value
127127
* @return bool
128128
*/
129-
PHP_FUNCTION(opencensus_trace_add_label)
129+
PHP_FUNCTION(opencensus_trace_add_attribute)
130130
{
131131
zend_string *k, *v;
132132
opencensus_trace_span_t *span;
@@ -139,21 +139,21 @@ PHP_FUNCTION(opencensus_trace_add_label)
139139
RETURN_FALSE;
140140
}
141141

142-
if (opencensus_trace_span_add_label(span, k, v) == SUCCESS) {
142+
if (opencensus_trace_span_add_attribute(span, k, v) == SUCCESS) {
143143
RETURN_TRUE;
144144
}
145145

146146
RETURN_FALSE;
147147
}
148148

149149
/**
150-
* Add a label to the root trace span
150+
* Add a attribute to the root trace span
151151
*
152152
* @param string $key
153153
* @param string $value
154154
* @return bool
155155
*/
156-
PHP_FUNCTION(opencensus_trace_add_root_label)
156+
PHP_FUNCTION(opencensus_trace_add_root_attribute)
157157
{
158158
zend_string *k, *v;
159159
opencensus_trace_span_t *span;
@@ -169,7 +169,7 @@ PHP_FUNCTION(opencensus_trace_add_root_label)
169169
/* fetch the first span */
170170
span = Z_PTR(OPENCENSUS_TRACE_G(spans)->arData->val);
171171

172-
if (opencensus_trace_span_add_label(span, k, v) == SUCCESS) {
172+
if (opencensus_trace_span_add_attribute(span, k, v) == SUCCESS) {
173173
RETURN_TRUE;
174174
}
175175

@@ -608,7 +608,7 @@ PHP_FUNCTION(opencensus_trace_method)
608608
PHP_FUNCTION(opencensus_trace_list)
609609
{
610610
opencensus_trace_span_t *trace_span;
611-
zval label, span;
611+
zval attribute, span;
612612

613613
array_init(return_value);
614614

@@ -625,8 +625,8 @@ PHP_FUNCTION(opencensus_trace_list)
625625
zend_update_property_double(opencensus_trace_span_ce, &span, "endTime", sizeof("endTime") - 1, trace_span->stop);
626626
zend_update_property_long(opencensus_trace_span_ce, &span, "kind", sizeof("kind") - 1, trace_span->kind);
627627

628-
ZVAL_ARR(&label, trace_span->labels);
629-
zend_update_property(opencensus_trace_span_ce, &span, "labels", sizeof("labels") - 1, &label);
628+
ZVAL_ARR(&attribute, trace_span->attributes);
629+
zend_update_property(opencensus_trace_span_ce, &span, "attributes", sizeof("attributes") - 1, &attribute);
630630

631631
zend_update_property(opencensus_trace_span_ce, &span, "backtrace", sizeof("backtrace") - 1, &trace_span->backtrace);
632632

ext/opencensus_trace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ PHP_FUNCTION(opencensus_trace_finish);
2929
PHP_FUNCTION(opencensus_trace_clear);
3030
PHP_FUNCTION(opencensus_trace_set_context);
3131
PHP_FUNCTION(opencensus_trace_context);
32-
PHP_FUNCTION(opencensus_trace_add_label);
33-
PHP_FUNCTION(opencensus_trace_add_root_label);
32+
PHP_FUNCTION(opencensus_trace_add_attribute);
33+
PHP_FUNCTION(opencensus_trace_add_root_attribute);
3434

3535
// Extension lifecycle hooks
3636
int opencensus_minit(INIT_FUNC_ARGS);

ext/opencensus_trace_span.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* protected $parentSpanId;
3333
* protected $startTime;
3434
* protected $endTime;
35-
* protected $labels;
35+
* protected $attributes;
3636
* protected $kind;
3737
*
3838
* public function __construct(array $spanOptions)
@@ -67,9 +67,9 @@
6767
* return $this->endTime;
6868
* }
6969
*
70-
* public function labels()
70+
* public function attributes()
7171
* {
72-
* return $this->labels;
72+
* return $this->attributes;
7373
* }
7474
*
7575
* public function kind()
@@ -159,18 +159,18 @@ static PHP_METHOD(OpenCensusTraceSpan, parentSpanId) {
159159
}
160160

161161
/**
162-
* Fetch the labels for the span
162+
* Fetch the attributes for the span
163163
*
164164
* @return array
165165
*/
166-
static PHP_METHOD(OpenCensusTraceSpan, labels) {
166+
static PHP_METHOD(OpenCensusTraceSpan, attributes) {
167167
zval *val, rv;
168168

169169
if (zend_parse_parameters_none() == FAILURE) {
170170
return;
171171
}
172172

173-
val = zend_read_property(opencensus_trace_span_ce, getThis(), "labels", sizeof("labels") - 1, 1, &rv);
173+
val = zend_read_property(opencensus_trace_span_ce, getThis(), "attributes", sizeof("attributes") - 1, 1, &rv);
174174

175175
RETURN_ZVAL(val, 1, 0);
176176
}
@@ -249,7 +249,7 @@ static zend_function_entry opencensus_trace_span_methods[] = {
249249
PHP_ME(OpenCensusTraceSpan, name, NULL, ZEND_ACC_PUBLIC)
250250
PHP_ME(OpenCensusTraceSpan, spanId, NULL, ZEND_ACC_PUBLIC)
251251
PHP_ME(OpenCensusTraceSpan, parentSpanId, NULL, ZEND_ACC_PUBLIC)
252-
PHP_ME(OpenCensusTraceSpan, labels, NULL, ZEND_ACC_PUBLIC)
252+
PHP_ME(OpenCensusTraceSpan, attributes, NULL, ZEND_ACC_PUBLIC)
253253
PHP_ME(OpenCensusTraceSpan, startTime, NULL, ZEND_ACC_PUBLIC)
254254
PHP_ME(OpenCensusTraceSpan, endTime, NULL, ZEND_ACC_PUBLIC)
255255
PHP_ME(OpenCensusTraceSpan, backtrace, NULL, ZEND_ACC_PUBLIC)
@@ -274,7 +274,7 @@ int opencensus_trace_span_minit(INIT_FUNC_ARGS) {
274274
zend_declare_property_null(opencensus_trace_span_ce, "startTime", sizeof("startTime") - 1, ZEND_ACC_PROTECTED TSRMLS_CC);
275275
zend_declare_property_null(opencensus_trace_span_ce, "endTime", sizeof("endTime") - 1, ZEND_ACC_PROTECTED TSRMLS_CC);
276276
zend_declare_property_null(opencensus_trace_span_ce, "kind", sizeof("kind") - 1, ZEND_ACC_PROTECTED TSRMLS_CC);
277-
zend_declare_property_null(opencensus_trace_span_ce, "labels", sizeof("labels") - 1, ZEND_ACC_PROTECTED TSRMLS_CC);
277+
zend_declare_property_null(opencensus_trace_span_ce, "attributes", sizeof("attributes") - 1, ZEND_ACC_PROTECTED TSRMLS_CC);
278278
zend_declare_property_null(opencensus_trace_span_ce, "backtrace", sizeof("backtrace") - 1, ZEND_ACC_PROTECTED TSRMLS_CC);
279279

280280
REGISTER_TRACE_SPAN_CONSTANT(KIND_UNKNOWN);
@@ -299,8 +299,8 @@ opencensus_trace_span_t *opencensus_trace_span_alloc()
299299
span->span_id = 0;
300300
span->start = 0;
301301
span->stop = 0;
302-
ALLOC_HASHTABLE(span->labels);
303-
zend_hash_init(span->labels, 4, NULL, ZVAL_PTR_DTOR, 0);
302+
ALLOC_HASHTABLE(span->attributes);
303+
zend_hash_init(span->attributes, 4, NULL, ZVAL_PTR_DTOR, 0);
304304
return span;
305305
}
306306

@@ -311,8 +311,8 @@ opencensus_trace_span_t *opencensus_trace_span_alloc()
311311
*/
312312
void opencensus_trace_span_free(opencensus_trace_span_t *span)
313313
{
314-
/* clear any allocated labels */
315-
FREE_HASHTABLE(span->labels);
314+
/* clear any allocated attributes */
315+
FREE_HASHTABLE(span->attributes);
316316
if (span->name) {
317317
zend_string_release(span->name);
318318
}
@@ -321,24 +321,24 @@ void opencensus_trace_span_free(opencensus_trace_span_t *span)
321321
efree(span);
322322
}
323323

324-
/* Add a label to the trace span struct */
325-
int opencensus_trace_span_add_label(opencensus_trace_span_t *span, zend_string *k, zend_string *v)
324+
/* Add a attribute to the trace span struct */
325+
int opencensus_trace_span_add_attribute(opencensus_trace_span_t *span, zend_string *k, zend_string *v)
326326
{
327327
/* put the string value into a zval and save it in the HashTable */
328328
zval zv;
329329
ZVAL_STRING(&zv, ZSTR_VAL(v));
330330

331-
if (zend_hash_update(span->labels, zend_string_copy(k), &zv) == NULL) {
331+
if (zend_hash_update(span->attributes, zend_string_copy(k), &zv) == NULL) {
332332
return FAILURE;
333333
} else {
334334
return SUCCESS;
335335
}
336336
}
337337

338-
/* Add a single label to the provided trace span struct */
339-
int opencensus_trace_span_add_label_str(opencensus_trace_span_t *span, char *k, zend_string *v)
338+
/* Add a single attribute to the provided trace span struct */
339+
int opencensus_trace_span_add_attribute_str(opencensus_trace_span_t *span, char *k, zend_string *v)
340340
{
341-
return opencensus_trace_span_add_label(span, zend_string_init(k, strlen(k), 0), v);
341+
return opencensus_trace_span_add_attribute(span, zend_string_init(k, strlen(k), 0), v);
342342
}
343343

344344
/* Update the provided span with the provided zval (array) of span options */
@@ -348,8 +348,8 @@ int opencensus_trace_span_apply_span_options(opencensus_trace_span_t *span, zval
348348
zval *v;
349349

350350
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARR_P(span_options), k, v) {
351-
if (strcmp(ZSTR_VAL(k), "labels") == 0) {
352-
zend_hash_merge(span->labels, Z_ARRVAL_P(v), zval_add_ref, 0);
351+
if (strcmp(ZSTR_VAL(k), "attributes") == 0) {
352+
zend_hash_merge(span->attributes, Z_ARRVAL_P(v), zval_add_ref, 0);
353353
} else if (strcmp(ZSTR_VAL(k), "startTime") == 0) {
354354
span->start = Z_DVAL_P(v);
355355
} else if (strcmp(ZSTR_VAL(k), "name") == 0) {

ext/opencensus_trace_span.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ typedef struct opencensus_trace_span_t {
3838
zend_long kind;
3939

4040
// zend_string* => zval*
41-
HashTable *labels;
41+
HashTable *attributes;
4242
} opencensus_trace_span_t;
4343

44-
int opencensus_trace_span_add_label(opencensus_trace_span_t *span, zend_string *k, zend_string *v);
45-
int opencensus_trace_span_add_label_str(opencensus_trace_span_t *span, char *k, zend_string *v);
44+
int opencensus_trace_span_add_attribute(opencensus_trace_span_t *span, zend_string *k, zend_string *v);
45+
int opencensus_trace_span_add_attribute_str(opencensus_trace_span_t *span, char *k, zend_string *v);
4646
int opencensus_trace_span_apply_span_options(opencensus_trace_span_t *span, zval *span_options);
4747
opencensus_trace_span_t *opencensus_trace_span_alloc();
4848
void opencensus_trace_span_free(opencensus_trace_span_t *span);

ext/package.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ This extension allows you to easily gather latency and other metadata by watchin
6666
<file name="function_kind_default.phpt" role="test" />
6767
<file name="function_kind_specified.phpt" role="test" />
6868
<file name="inherit_context.phpt" role="test" />
69-
<file name="labels.phpt" role="test" />
69+
<file name="attributes.phpt" role="test" />
7070
<file name="manual_spans.phpt" role="test" />
7171
<file name="manual_spans_default_options.phpt" role="test" />
7272
<file name="many_spans_test.phpt" role="test" />
@@ -80,11 +80,11 @@ This extension allows you to easily gather latency and other metadata by watchin
8080
<file name="method_kind_specified.phpt" role="test" />
8181
<file name="module_callback_static_string.phpt" role="test" />
8282
<file name="nested_spans.phpt" role="test" />
83-
<file name="non-string-labels-function-callback.phpt" role="test" />
84-
<file name="non-string-labels-function.phpt" role="test" />
85-
<file name="non-string-labels-method-callback.phpt" role="test" />
86-
<file name="non-string-labels-method.phpt" role="test" />
87-
<file name="non-string-labels.phpt" role="test" />
83+
<file name="non-string-attributes-function-callback.phpt" role="test" />
84+
<file name="non-string-attributes-function.phpt" role="test" />
85+
<file name="non-string-attributes-method-callback.phpt" role="test" />
86+
<file name="non-string-attributes-method.phpt" role="test" />
87+
<file name="non-string-attributes.phpt" role="test" />
8888
<file name="span_class.phpt" role="test" />
8989
<file name="static_method_callback_scope.phpt" role="test" />
9090
<file name="static_method_test.phpt" role="test" />

ext/span.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Span {
3232
protected $parentSpanId;
3333
protected $startTime;
3434
protected $endTime;
35-
protected $labels;
35+
protected $attributes;
3636
protected $kind;
3737

3838
public function __construct(array $spanOptions)
@@ -67,9 +67,9 @@ public function endTime()
6767
return $this->endTime;
6868
}
6969

70-
public function labels()
70+
public function attributes()
7171
{
72-
return $this->labels;
72+
return $this->attributes;
7373
}
7474

7575
public function kind()

ext/tests/basic_class_function.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ echo "Span startTime is a double: $test\n";
2424
$test = gettype($span->endTime()) == 'double';
2525
echo "Span endTime is a double: $test\n";
2626

27-
var_dump($span->labels());
27+
var_dump($span->attributes());
2828

2929
?>
3030
--EXPECT--

ext/tests/basic_function.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ echo "Span startTime is a double: $test\n";
2323
$test = gettype($span->endTime()) == 'double';
2424
echo "Span endTime is a double: $test\n";
2525

26-
var_dump($span->labels());
26+
var_dump($span->attributes());
2727
?>
2828
--EXPECT--
2929
Number of traces: 1

ext/tests/closure_exeception.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once(__DIR__ . '/common.php');
88
opencensus_trace_function("foo", function ($x) {
99
// should be an exception
1010
echo $x->bar();
11-
return ['name' => 'foo', 'startTime' => 0.1, 'labels' => ['asdf' => 'qwer' . $x, 'zxcv' => 'jkl;']];
11+
return ['name' => 'foo', 'startTime' => 0.1, 'attributes' => ['asdf' => 'qwer' . $x, 'zxcv' => 'jkl;']];
1212
});
1313
foo(3);
1414
?>

0 commit comments

Comments
 (0)