-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Adds GoogleLogger to Diagnostics.Common #6657
feat: Adds GoogleLogger to Diagnostics.Common #6657
Conversation
(build error is because of the language version missmatch, I'll figure it out, but this is all green on local so it's ready for review). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'm glad you've got a handle on this... it looks okay to me, but it's slightly hard to follow what's going on, despite your evident care in creating the commits separately... it's just inherently complex.
Looks fine as far as I can see... if you're confident in it, let's merge (once the language issues have been fixed) and release a beta.
@@ -545,11 +547,11 @@ public async Task Logging_Trace_External_OneEntry(TestServer server) | |||
LogEntry entry = Assert.Single(results); | |||
|
|||
// And the resource name of the trace associated to it contains the external trace id. | |||
Assert.Contains(TestEnvironment.GetTestProjectId(), entry.Trace); | |||
Assert.Contains("external_trace_id", entry.Trace); | |||
Assert.Contains(TestEnvironment.GetTestProjectId(), entry.Trace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
string fullTraceName = TraceTarget.ForProject(ProjectId).GetFullTraceName(traceId); | ||
|
||
Predicate<IEnumerable<LogEntry>> matcher = logEntries => | ||
{ | ||
LogEntry entry = logEntries.Single(); | ||
return entry.LogName == new LogName(ProjectId, BaseLogName).ToString() && | ||
entry.Trace == fullTraceName && | ||
entry.SpanId == spanId; | ||
entry.SpanId == $"{spanId:x16}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear to me why this had to change. Is it because we're not requiring the external span IDs to be 64-bit integers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the now obsolete TraceContextForLogEntry has a string for SpanId, and docs saying that it should be in base 16. But now we use the new ITraceContext where span ID is a ulong, and for setting it in the entry we are the ones who have to convert it to base 16.
@@ -33,6 +33,7 @@ namespace Google.Cloud.Diagnostics.AspNetCore | |||
/// These values can be attached to a log entry to establish the | |||
/// relation of it and a trace. | |||
/// </summary> | |||
[Obsolete("Use Common.ITraceContext instead.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe fully-qualify this name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -67,10 +67,12 @@ private string Formatter(string message, Exception ex) | |||
Common.LoggerOptions options = Common.LoggerOptions.CreateWithServiceContext( | |||
logLevel, logName, labels, monitoredResource, retryOptions: retryOptions, serviceName: serviceName, version: version); | |||
#pragma warning disable CS0618 // Type or member is obsolete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this pragma?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the one that is used to keep backward compatibility.
@@ -23,7 +23,7 @@ namespace Google.Cloud.Diagnostics.Common | |||
/// Extension methods for converting KeyValuePair Enumerables to several types, | |||
/// including Protobuf well known types. | |||
/// </summary> | |||
public static class KeyValuePairEnumerableExtensions | |||
internal static class KeyValuePairEnumerableExtensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a breaking change because it was introduced since the last release, yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's just one from the previous PR.
{ | ||
} | ||
|
||
[Obsolete("Added for backward compatibility only when moving GoogleLogger to Common.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm somewhat lost as to whether we actually still need this. Given that it's internal, I'd expect to be able to remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the one remaining piece that allows us to use the Common.GoogleLogger from the AspNetCore.GoogleLogger taking into account some of the obsolte types that remained in AspNetCore* that were not moved to Common. This is called from Common.GoogleLoggleProvider which is called from AspNetCore.GoogleLoggerProvider. I added the Obsolete attribute so that we ourselves know not to depend on it.
b6cf5f3
to
8c05176
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed all comments and fixed the language version mismatch. Will wait on green for merging.
@@ -545,11 +547,11 @@ public async Task Logging_Trace_External_OneEntry(TestServer server) | |||
LogEntry entry = Assert.Single(results); | |||
|
|||
// And the resource name of the trace associated to it contains the external trace id. | |||
Assert.Contains(TestEnvironment.GetTestProjectId(), entry.Trace); | |||
Assert.Contains("external_trace_id", entry.Trace); | |||
Assert.Contains(TestEnvironment.GetTestProjectId(), entry.Trace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -67,10 +67,12 @@ private string Formatter(string message, Exception ex) | |||
Common.LoggerOptions options = Common.LoggerOptions.CreateWithServiceContext( | |||
logLevel, logName, labels, monitoredResource, retryOptions: retryOptions, serviceName: serviceName, version: version); | |||
#pragma warning disable CS0618 // Type or member is obsolete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the one that is used to keep backward compatibility.
string fullTraceName = TraceTarget.ForProject(ProjectId).GetFullTraceName(traceId); | ||
|
||
Predicate<IEnumerable<LogEntry>> matcher = logEntries => | ||
{ | ||
LogEntry entry = logEntries.Single(); | ||
return entry.LogName == new LogName(ProjectId, BaseLogName).ToString() && | ||
entry.Trace == fullTraceName && | ||
entry.SpanId == spanId; | ||
entry.SpanId == $"{spanId:x16}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the now obsolete TraceContextForLogEntry has a string for SpanId, and docs saying that it should be in base 16. But now we use the new ITraceContext where span ID is a ulong, and for setting it in the entry we are the ones who have to convert it to base 16.
@@ -33,6 +33,7 @@ namespace Google.Cloud.Diagnostics.AspNetCore | |||
/// These values can be attached to a log entry to establish the | |||
/// relation of it and a trace. | |||
/// </summary> | |||
[Obsolete("Use Common.ITraceContext instead.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -23,7 +23,7 @@ namespace Google.Cloud.Diagnostics.Common | |||
/// Extension methods for converting KeyValuePair Enumerables to several types, | |||
/// including Protobuf well known types. | |||
/// </summary> | |||
public static class KeyValuePairEnumerableExtensions | |||
internal static class KeyValuePairEnumerableExtensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's just one from the previous PR.
{ | ||
} | ||
|
||
[Obsolete("Added for backward compatibility only when moving GoogleLogger to Common.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the one remaining piece that allows us to use the Common.GoogleLogger from the AspNetCore.GoogleLogger taking into account some of the obsolte types that remained in AspNetCore* that were not moved to Common. This is called from Common.GoogleLoggleProvider which is called from AspNetCore.GoogleLoggerProvider. I added the Obsolete attribute so that we ourselves know not to depend on it.
Looks like there are a couple of doc-comment issues and some compatibility issues. I'm happy to look at the compatibility ones if you'd like. |
This allows easier use of GoogleLogger in non ASP.NET Core applications. Towards googleapis#6367 - Replicate LoggerOptions in Common. - And have AspNetCore*.LoggerOptions be just a wrapper of Common.LoggerOptions. - Copies ILogEntryLabelProvider to Common. - And marks the one in AspNetCore* Obsolete. - Makes AspNetCore*.IExternalTraceProvider obsolete. - It can now be replaced by Common.ITraceContext.
8c05176
to
e30a1f1
Compare
I'm looking, but the doc comments one are not a problem on local, so I'm not sure what's happening. |
Doc-comment issues fixed. The compaibility differences I'm pretty sure are not a problem, but a second pair of eyes would be great. I think is just the tool that's being more strict than it needs to. |
These are:
|
Merging with admin rights. Although the breaking changes are theoretically breaking, we don't expect them to actually cause any issues in this case. Will note this in the release notes. |
As always, one commit at a time, although I'll rebase everything into one before merging.
We can make more AspNetCore* types obsolete, and I also want to improve docs, but I think this is now good for a beta release.