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

Add file where function is defined to trace attributes #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions ext/opencensus_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,19 @@ static zend_string *opencensus_trace_add_scope_name(zend_string *function_name,
return result;
}

/* Get location of the file where this function is defiend */
static zend_string *opencensus_trace_file_name(zend_class_entry *scope)
{
zend_string *result;

if (scope && &scope->info != NULL && &scope->info.user != NULL) {
result = zend_string_copy(scope->info.user.filename);
} else{
return NULL;
}
return result;
}

/**
* Start a new trace span
*
Expand Down Expand Up @@ -619,6 +632,10 @@ void opencensus_trace_execute_ex (zend_execute_data *execute_data TSRMLS_DC) {
EG(current_execute_data)->func->common.function_name,
EG(current_execute_data)->func->common.scope
);
zend_string *file_name = opencensus_trace_file_name(
EG(current_execute_data)->func->common.scope
);

zval *trace_handler;
opencensus_trace_span_t *span;
zend_string *callback_name = NULL;
Expand Down Expand Up @@ -660,6 +677,10 @@ void opencensus_trace_execute_ex (zend_execute_data *execute_data TSRMLS_DC) {
}
}
zend_string_release(callback_name);
if (file_name != NULL) {
opencensus_trace_span_add_attribute_str(span, "file", file_name);
zend_string_release(file_name);
}
opencensus_trace_finish();
}

Expand All @@ -686,6 +707,10 @@ void opencensus_trace_execute_internal(INTERNAL_FUNCTION_PARAMETERS)
execute_data->func->internal_function.function_name,
execute_data->func->internal_function.scope
);
zend_string *file_name = opencensus_trace_file_name(
execute_data->func->internal_function.scope
);

zval *trace_handler;
opencensus_trace_span_t *span;
zend_string *callback_name = NULL;
Expand Down Expand Up @@ -726,6 +751,10 @@ void opencensus_trace_execute_internal(INTERNAL_FUNCTION_PARAMETERS)
opencensus_trace_span_apply_span_options(span, trace_handler);
}
}
if (file_name != NULL) {
opencensus_trace_span_add_attribute_str(span, "file", file_name);
zend_string_release(file_name);
}
zend_string_release(callback_name);
opencensus_trace_finish();
}
Expand Down