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

fix zipkin v2 #145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion example/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

sh ./zipkin.sh

php -d extension=molten.so -d molten.enable=1 -d molten.sink_type=4 -d molten.tracing_cli=1 -d molten.sink_http_uri=http://127.0.0.1:9411/api/v1/spans -d molten.service_name=php_test -d molten.sampling_rate=1 -r '$c=curl_init("http://localhost:12345");curl_exec($c);'
php -d extension=molten.so -d molten.enable=1 -d molten.sink_type=4 -d molten.tracing_cli=1 -d molten.sink_http_uri=http://127.0.0.1:9411/api/v2/spans -d molten.span_format=zipkin_v2 -d molten.service_name=php_test -d molten.sampling_rate=1 -r '$c=curl_init("http://localhost:12345");curl_exec($c);'
2 changes: 1 addition & 1 deletion example/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function server_start($hostname, $port, $router, $sn) {
$cmd .= " {$router}";
$handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true));
} else {
$cmd = "exec {$php_executable} -t {$doc_root} -n -d extension=molten.so -d molten.enable=1 -d molten.sink_type=4 -d molten.sink_http_uri=http://127.0.0.1:9411/api/v1/spans -d molten.service_name={$sn} -d molten.sampling_rate_base=1 -S " . $address;
$cmd = "exec {$php_executable} -t {$doc_root} -d extension=molten.so -d molten.enable=1 -d molten.sink_type=4 -d molten.span_format=zipkin_v2 -d molten.sink_http_uri=http://127.0.0.1:9411/api/v2/spans -d molten.service_name={$sn} -d molten.sampling_rate_base=1 -S " . $address;
$cmd .= " {$router}";
$cmd .= " 2>/dev/null";
$handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root);
Expand Down
34 changes: 15 additions & 19 deletions molten_span.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,30 +164,16 @@ void zn_v2_start_span(zval **span, char *service_name, char *trace_id, char *spa
if (parent_id != NULL) {
mo_add_assoc_string(*span, "parentId", parent_id, 1);
}
add_assoc_long(*span, "timestampMicros", timestamp);
add_assoc_long(*span, "durationMicros", duration);
add_assoc_long(*span, "timestamp", timestamp);
add_assoc_long(*span, "duration", duration);

/* add local Endpoint */
zval *local_endpoint;
MO_ALLOC_INIT_ZVAL(local_endpoint);
array_init(local_endpoint);
add_assoc_zval(*span, "localEndpoint", local_endpoint);

/* add remote endpoint */
zval *remote_endpoint;
MO_ALLOC_INIT_ZVAL(remote_endpoint);
array_init(remote_endpoint);
add_assoc_zval(*span, "remoteEndpoint", remote_endpoint);

/* add tags */
zval *tags;
MO_ALLOC_INIT_ZVAL(tags);
array_init(tags);
add_assoc_zval(*span, "tags", tags);

/* free */
MO_FREE_ALLOC_ZVAL(local_endpoint);
MO_FREE_ALLOC_ZVAL(remote_endpoint);
MO_FREE_ALLOC_ZVAL(tags);
}
/* }}} */
Expand All @@ -202,11 +188,21 @@ void zn_v2_add_endpoint(zval *span, bool is_local, char *service_name, char *ipv
zval *endpoint;
if (is_local) {
if (mo_zend_hash_zval_find(Z_ARRVAL_P(span), "localEndpoint", sizeof("localEndpoint"), (void **)&endpoint) == FAILURE) {
return;
/* add local Endpoint */
zval *local_endpoint;
MO_ALLOC_INIT_ZVAL(local_endpoint);
array_init(local_endpoint);
add_assoc_zval(span, "localEndpoint", local_endpoint);
endpoint=local_endpoint;
}
} else {
if (mo_zend_hash_zval_find(Z_ARRVAL_P(span), "remoteEndpoint", sizeof("remoteEndpoint"), (void **)&endpoint) == FAILURE) {
return;
if (mo_zend_hash_zval_find(Z_ARRVAL_P(span), "remoteEndpoint", sizeof("remoteEndpoint"), (void **)&endpoint) == FAILURE) {
/* add remote endpoint */
zval *remote_endpoint;
MO_ALLOC_INIT_ZVAL(remote_endpoint);
array_init(remote_endpoint);
add_assoc_zval(span, "remoteEndpoint", remote_endpoint);
endpoint=remote_endpoint;
}
}

Expand Down