opencensus-java
opencensus-java copied to clipboard
trace/Span: provide a method for retroactively constructing a span given startTime and endTime
Please answer these questions before submitting a bug report.
What version of OpenCensus are you using?
0.15.0
The old style APM agnosticity for many drivers is to provide an API that allows users to set hook/listeners for events such as:
- Started
- Succeeded
- Failed
I am currently working on a task to get MongoDB driver instrumentation using that old style, because instrumenting their driver for traces and metrics has proven to be tricky and require a bit of convincing.
Anyways, their API allows users to set event listeners for the various events
- Started http://mongodb.github.io/mongo-java-driver/3.6/javadoc/com/mongodb/event/CommandStartedEvent.html
- Succeeded http://mongodb.github.io/mongo-java-driver/3.6/javadoc/com/mongodb/event/CommandSucceededEvent.html
- Failed http://mongodb.github.io/mongo-java-driver/3.6/javadoc/com/mongodb/event/CommandFailedEvent.html
and I have been able to successfully create an event listener and send metrics to a backend e.g using Stackdriver Monitoring and this is what I currently have https://github.com/orijtech/mongodb-apm:
with code at https://github.com/orijtech/mongodb-apm/blob/5054039181298ac13f7b284cd3d77e9510435b1e/src/main/java/io/opencensus/apm/EventListener.java#L1-L233
with a runnable demo at https://github.com/orijtech/mongodb-apm/blob/5054039181298ac13f7b284cd3d77e9510435b1e/src/main/java/io/opencensus/apm/Inspector.java#L1-L85
Problem
The current trace APIs don't allow one to retroactively create a trace if we know its startTime and endTime. We are only able to start and end traces but never to be able to create a trace with information of an already timed operation and then let the trace be exported
Proposal
- Please provide an API that will allow one to create a span if I know the startTime and endTime, name and whatever annotations I'd like to place
- A method to process the span as end would to send it to the spanStore or exporters
I think this is Java-specific since Go already has a mechanism of constructing a Span from SpanData.
Also we have same issue due to limitation of HttpServletRequest#setCharacterEncoding()
. In the start of request, we cannot touch request parameter/body due to Servlet API limitation of it.
This method must be called prior to reading request parameters or reading input https://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#setCharacterEncoding%28java.lang.String%29
So that we want to construct trace after we called setCharacterEncoding()
, it is not start of the request.