Skip to content
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
23 changes: 23 additions & 0 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,29 @@ describe("Opentracing interface", () => {
expect(zipkinTracer.recordBinary).toHaveBeenCalledWith("data", "42");
});

it("should log all data in string format", () => {
const data = { user: "johndoe" };
const id = 345;
span.log({ event: "data_received", data, id });

// should do it in a scope
expect(zipkinTracer.scoped).toHaveBeenCalled();
zipkinTracer.scoped.mock.calls[0][0]();

expect(zipkinTracer.recordBinary).toHaveBeenCalledWith(
"event",
"data_received"
);
expect(zipkinTracer.recordBinary).toHaveBeenCalledWith(
"data",
JSON.stringify(data)
);
expect(zipkinTracer.recordBinary).toHaveBeenCalledWith(
"id",
JSON.stringify(id)
);
});

it("should use the right id in log", () => {
const otherSpan = tracer.startSpan("Other Span", {
kind: "client"
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ function SpanCreator({ tracer, serviceName, kind }) {
tracer.setId(this.id);

Object.entries(obj).map(([key, value]) => {
tracer.recordBinary(key, value);
tracer.recordBinary(
key,
typeof value !== "string" ? JSON.stringify(value) : value
);
});
});
}
Expand Down Expand Up @@ -294,6 +297,7 @@ class Tracing {
}
}


// These values should match https://github.com/opentracing/opentracing-javascript/blob/master/src/constants.ts
Tracing.FORMAT_TEXT_MAP = FORMAT_TEXT_MAP;
Tracing.FORMAT_HTTP_HEADERS = FORMAT_HTTP_HEADERS;
Expand Down