Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Sets trace ID in log entries correctly #683

Merged
merged 5 commits into from
May 17, 2018
Merged

Conversation

joaoandremartins
Copy link
Contributor

Adds a new logging enhancer that sets the right field for the log
entries to be linkable from a trace, in the Google Cloud Console.
Also updates Trace code sample to show this capability.

Fixes #664

Adds a new logging enhancer that sets the right field for the log
entries to be linkable from a trace, in the Google Cloud Console.
Also updates Trace code sample to show this capability.

Fixes #664
You should see the trace information in detail.
Additionally, if you logged in with the Google Cloud SDK or have the `GOOGLE_CLOUD_PROJECT` environment variable set to your GCP project ID, you can also click the `View` link in front of the `Details` -> `Log` to view the log entries related to that trace ID.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really the only addition here. The rest is just putting sentences in the same line.


@Override
public void enhanceLogEntry(LogEntry.Builder builder) {
String projectId = new DefaultGcpProjectIdProvider().getProjectId();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If projectId is empty or null, there is really no suitable alternative, so it's safe if the final result is projects//traces/traceId or projects/null/traces/traceId.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really safe to call here new DefaultGcpProjectIdProvider()? What if I use fully different projectId strategy in my project?

May we somehow workaround with the system property or make that setCurrentTraceId aware about the projectId as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree we should be doing this because the devsite mentions this format (https://cloud.google.com/trace/docs/viewing-details#log_entries) . But it makes me wonder why that other TraceLoggingEnhancer we were using even exists? the "trace_id" label that other one uses isn't mentioned in that devsite link at all... Should we set both ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no harm in doing so, I think we should do both. In that case I think you could even extend TraceLoggingEnhancer from the client lib and just override that single method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a new issue in google-cloud-java so they fix their current implementation. googleapis/google-cloud-java#3280

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really only need the trace ID in one place, it's not being used for anything in labels.trace_id.
Probably better not to add any more complexity where it's not necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me

Copy link
Contributor

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I understand everything here, so forgive me my ignorance comments if that...

public void enhanceLogEntry(LogEntry.Builder builder) {
String projectId = new DefaultGcpProjectIdProvider().getProjectId();
String traceId = getTraceId();
if (traceId != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like if traceId == null, the projectId is redundant, therefore we even don't need to create a DefaultGcpProjectIdProvider instance in that case.

Just suggestion for minor optimization...


@Override
public void enhanceLogEntry(LogEntry.Builder builder) {
String projectId = new DefaultGcpProjectIdProvider().getProjectId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really safe to call here new DefaultGcpProjectIdProvider()? What if I use fully different projectId strategy in my project?

May we somehow workaround with the system property or make that setCurrentTraceId aware about the projectId as well?

Copy link
Contributor

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but need to be rebased after #685 to be sure that Travis is OK with the changes.

@joaoandremartins joaoandremartins merged commit 0175ff6 into master May 17, 2018
@joaoandremartins joaoandremartins deleted the gh-664-trace-id branch May 17, 2018 19:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants