Skip to content
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

Support customization of timestamp format #398

Merged

Conversation

stanhu
Copy link
Contributor

@stanhu stanhu commented Feb 12, 2021

By default, RFC3339 timestamps are used, but our application uses a
custom format. This commit enables us to set the format in a consistent
manner.

Closes #131

By default, RFC3339 timestamps are used, but our application uses a
custom format. This commit enables us to set the format in a consistent
manner.

Closes grpc-ecosystem#131
Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

LGTM

@johanbrandhorst johanbrandhorst merged commit be4c235 into grpc-ecosystem:master Feb 13, 2021
@johanbrandhorst
Copy link
Collaborator

Thanks for your contribution! Could you please cherry pick this against v2? It may need significant refactoring but it'd be good to have in the new version too.

@stanhu
Copy link
Contributor Author

stanhu commented Feb 13, 2021

@johanbrandhorst Sure, I took a look at the v2 branch. It looks like the new payload interceptors have a bit different signature from logging.interceptors:

// PayloadUnaryServerInterceptor returns a new unary server interceptors that logs the payloads of requests on INFO level.
// Logger tags will be used from tags context.
func PayloadUnaryServerInterceptor(logger Logger, decider ServerPayloadLoggingDecider) grpc.UnaryServerInterceptor {
return interceptors.UnaryServerInterceptor(&payloadReportable{logger: logger, serverDecider: decider})
}
// PayloadStreamServerInterceptor returns a new server server interceptors that logs the payloads of requests on INFO level.
// Logger tags will be used from tags context.
func PayloadStreamServerInterceptor(logger Logger, decider ServerPayloadLoggingDecider) grpc.StreamServerInterceptor {
return interceptors.StreamServerInterceptor(&payloadReportable{logger: logger, serverDecider: decider})
}
// PayloadUnaryClientInterceptor returns a new unary client interceptor that logs the paylods of requests and responses on INFO level.
// Logger tags will be used from tags context.
func PayloadUnaryClientInterceptor(logger Logger, decider ClientPayloadLoggingDecider) grpc.UnaryClientInterceptor {
return interceptors.UnaryClientInterceptor(&payloadReportable{logger: logger, clientDecider: decider})
}
// PayloadStreamClientInterceptor returns a new streaming client interceptor that logs the paylods of requests and responses on INFO level.
// Logger tags will be used from tags context.
func PayloadStreamClientInterceptor(logger Logger, decider ClientPayloadLoggingDecider) grpc.StreamClientInterceptor {
return interceptors.StreamClientInterceptor(&payloadReportable{logger: logger, clientDecider: decider})
}

It doesn't seem like we can reuse logging.Options here because the Decider and ClientPayloadLoggingDecider signatures are different here. A few options:

  1. Introduce a PayloadOptions
  2. Tack on the format to the end of each function
  3. Expand the Logging interface to set timestamp formatting optoins

@johanbrandhorst
Copy link
Collaborator

CC @bwplotka

stanhu added a commit to stanhu/go-grpc-middleware that referenced this pull request Feb 13, 2021
stanhu added a commit to stanhu/go-grpc-middleware that referenced this pull request Feb 13, 2021
@stanhu
Copy link
Contributor Author

stanhu commented Feb 13, 2021

I did the simplest thing with option 2 in #399, but I don't love it. Feel free to refactor as necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

grpc.request.deadline and grpc.start_time precision is in seconds
2 participants