yammer / telemetry

A dapper-like substance in Java.
Apache License 2.0
19 stars 6 forks source link

log file is empty when telemetry-example run #10

Open jkwebster opened 8 years ago

jkwebster commented 8 years ago

Hi,I wanna run telemetry-example,but the "telemetry.log" is empty,and there is also no database action when I type "http://localhost:8080/delayed/start/66/duration/66",would you please tell me what's wrong with it? PS,my command is : java -javaagent:telemetry-agent-0.0.3-SNAPSHOT.jar=/Users/projs/telemetry-example/telemetry.yml -jar target/telemetry-example-0.0.3-SNAPSHOT.jar server example.yml.

Thanks

ryankennedy commented 8 years ago

Make sure you've run the database migrations first as you need to create the table structure that the service will write into:

java  -jar target/telemetry-example-0.0.3-SNAPSHOT.jar db migrate example.yml

Once you have that, you'll need to make a small tweak to telemetry-example/telemetry.log to set sampler=on (I have no idea why it's set to off in the repo). Then run the server:

java -javaagent:../telemetry-agent/target/telemetry-agent-0.0.3-SNAPSHOT.jar=telemetry.yml -jar target/telemetry-example-0.0.3-SNAPSHOT.jar server example.yml

Now request the URL again and you should get some output in telemetry.log:

{"trace_id":6938483763677048656,"span_id":2520803622,"name":"GET http://localhost:8080/delayed/start/66/duration/66","host":"helium.local","pid":16711,"start_time":1444711028528000000,"annotations":[{"logged_at":1444711028530000000,"name":"ServerReceived"},{"logged_at":1444711028530000000,"name":"ServiceName","message":"example"},{"logged_at":1444711028559000000,"name":"Start Timer","message":"\"com.yammer.telemetry.example.resources\":type=\"DelayedWriteResource\",name=\"delayedWrite\""},{"logged_at":1444711028561000000,"name":"Scheduled Task","message":"com.yammer.telemetry.example.resources.DelayedWriteResource$1"},{"logged_at":1444711028569000000,"name":"Stop Timer","message":"\"com.yammer.telemetry.example.resources\":type=\"DelayedWriteResource\",name=\"delayedWrite\""},{"logged_at":1444711028579000000,"name":"ServerSent"}],"duration":50531000}
{"trace_id":6938483763677048656,"span_id":2520803622,"name":"com.yammer.telemetry.example.resources.DelayedWriteResource$1","host":"helium.local","pid":16711,"start_time":1444711028637000000,"annotations":[{"logged_at":1444711028637000000,"name":"Before","message":"com.yammer.telemetry.example.resources.DelayedWriteResource$1"},{"logged_at":1444711028637000000,"name":"Start Timer","message":"\"com.yammer.telemetry.example.resources\":type=\"DelayedWriteResource\",name=\"delayed-write\""},{"logged_at":1444711028637000000,"name":"After","message":"com.yammer.telemetry.example.resources.DelayedWriteResource$1"}],"duration":230000}
jkwebster commented 8 years ago

Thanks much,I can run it well now,but another qeustion,how to use log4j or slf4j to print logging info? Because we all mostly like to search WARNING or ERROR messages with trace_id and span_id.

ryankennedy commented 8 years ago

Are you asking for trace/span IDs in your application logs or for warning/error messages to be attached to the trace/span? Either should be feasible. If you want the trace/span ID in your application logs you'd need to tap into MDC (Mapped Diagnostic Context), which is supported by both log4j and slf4j. Some minor modifications to telemetry would be sufficient to add trace and span IDs to the MDC.

If you want warnings and/or errors to be attached to spans, an agent handler could be written to intercept calls to warn/error and attach them as span annotations.

I no longer work at Yammer and am no longer doing active development on telemetry (neither is Yammer as far as I can tell), so you may need to pursue this on your own if you want it.