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

Use structured logs and export traces #1831

Merged
merged 1 commit into from
Jan 11, 2022

Conversation

carolynvs
Copy link
Member

@carolynvs carolynvs commented Nov 17, 2021

What does this change

Log to a file in ~/.porter/logs/CORRELLATION_ID.json and in colored human readable
output to stderr. When stderr is not a TTY, color is omitted (which is
what we need for piping to a file or running on headless CI servers).

Tracing has been enabled using open-telemetry and can be configured with
the standard OTEL environment variables.

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specify-protocol

This is just a stub of the final tracing and log switch over, that lays
down a framework for converting the rest and instrumenting more
commands. For now we start a trace for the command executed,
a little bit of the execute bundle flow, and the buildkit build driver.

If a trace cannot be written to the server (due to misconfiguration or the trace endpoint is offline),
porter will keep on truckin' and print something like this:

$ porter upgrade test3
executing upgrade action from porter-hello (installation: test3)
No existing bundle state to unpack
World 2.0
World 2.0
Packing bundle state...
execution completed successfully!
2021/11/18 12:02:20 traces exporter is disconnected from the server localhost:4317: grpc: no transport security set (use grpc.WithInsecure() explicitly or set credentials)

Updated documentation

What issue does it fix

Closes #1429

Notes for the reviewer

Checklist

  • Unit Tests
  • Documentation
  • Schema (porter.yaml)

@@ -63,7 +63,7 @@ func buildBundleBuildCommand(p *porter.Porter) *cobra.Command {
return opts.Validate(p)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.Build(opts)
return p.Build(cmd.Context(), opts)
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI, short of using global package variables (which would cause problems for anyone using porter as a library) we are going to just have to pass context around everywhere going forward.

It's useful for other things, like cancel support, so it's not the worst, just ugly. 😀

@carolynvs carolynvs force-pushed the structured-logging branch 2 times, most recently from 96320a8 to fd6984b Compare November 17, 2021 22:31
if b.IsVerbose() {
out = b.Out
if b.IsVerbose() || b.Config.IsFeatureEnabled(experimental.FlagStructuredLogs) {
ctx, log = log.StartSpan("buildkit", attribute.String("source", "porter.build.buildkit"))
Copy link
Member Author

Choose a reason for hiding this comment

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

I would like to have a source set for all log lines to help filter by source. It will need more experimentation though so for now I'm using it just here and we can complete that in a follow-up if it turns out to be helpful.

@carolynvs carolynvs marked this pull request as ready for review November 23, 2021 14:22
@carolynvs
Copy link
Member Author

@vdice This is a big PR and I'm out on leave for the rest of the year. Just giving you time to review or try it out locally. I won't attempt to get this merged until when I'm back in January.

Log to a file in ~/.porter/logs/CORRELLATION_ID.json and in colored human readable
output to stderr. When stderr is not a TTY, color is omitted (which is
what we need for piping to a file or running on headless CI servers).

Tracing has been enabled using open-telemetry and can be configured with
the standard OTEL environment variables.

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specify-protocol

This is just a stub of the final tracing and log switch over, that lays
down a framework for converting the rest and instrumenting more
commands. For now we start a trace for the command executed.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
Copy link
Member

@vdice vdice left a comment

Choose a reason for hiding this comment

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

LGTM! 👏

@carolynvs carolynvs merged commit 3ddefb4 into getporter:release/v1 Jan 11, 2022
@carolynvs carolynvs deleted the structured-logging branch January 11, 2022 20:01
This was referenced Jan 11, 2022
carolynvs added a commit to carolynvs/porter that referenced this pull request Jan 12, 2022
The integration tests accidentally were passing nil for the context
after I added context.Context as a parameter to some Porter commands in getporter#1831.
This passes in context.Background to fix the nil pointer exceptions that
was causing.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
joshuabezaleel pushed a commit to joshuabezaleel/porter that referenced this pull request Feb 8, 2022
The integration tests accidentally were passing nil for the context
after I added context.Context as a parameter to some Porter commands in getporter#1831.
This passes in context.Background to fix the nil pointer exceptions that
was causing.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
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.

2 participants