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

Add a tracer to send (legacy) Azure Event Hub SDK logs to logp #40451

Merged
merged 5 commits into from
Aug 23, 2024
Merged
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
62 changes: 31 additions & 31 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10907,6 +10907,37 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Dependency : github.com/devigned/tab
Version: v0.1.2-0.20190607222403-0c15cf42f9a2
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/devigned/[email protected]/LICENSE:

MIT License

Copyright (c) 2019 David Justice

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


--------------------------------------------------------------------------------
Dependency : github.com/dgraph-io/badger/v3
Version: v3.2103.1
Expand Down Expand Up @@ -37209,37 +37240,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


--------------------------------------------------------------------------------
Dependency : github.com/devigned/tab
Version: v0.1.2-0.20190607222403-0c15cf42f9a2
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/devigned/[email protected]/LICENSE:

MIT License

Copyright (c) 2019 David Justice

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


--------------------------------------------------------------------------------
Dependency : github.com/elastic/ristretto
Version: v0.1.1-0.20220602190459-83b0895ca5b3
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f
github.com/denisenkom/go-mssqldb v0.12.3
github.com/devigned/tab v0.1.2-0.20190607222403-0c15cf42f9a2 // indirect
github.com/devigned/tab v0.1.2-0.20190607222403-0c15cf42f9a2
github.com/dgraph-io/badger/v3 v3.2103.1
github.com/digitalocean/go-libvirt v0.0.0-20240709142323-d8406205c752
github.com/docker/docker v26.1.5+incompatible
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/include/list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

117 changes: 117 additions & 0 deletions x-pack/filebeat/input/azureeventhub/tracer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !aix

package azureeventhub

import (
"context"

"github.com/devigned/tab"

"github.com/elastic/elastic-agent-libs/logp"
)

func init() {
tab.Register(new(logsOnlyTracer))
}

// logsOnlyTracer manages the creation of the required
// Spanners and Loggers with the goal of deferring logging
// to the `logp` package.
//
// According to the `github.com/devigned/tab package`,
// to implement a Tracer, you must provide the following
// three components:
//
// - Tracer
// - Spanner
// - Logger
//
// Since we are currently only interested in logging, we will
// implement a Tracer that only logs.
type logsOnlyTracer struct{}

// ----------------------------------------------------------------------------
// Tracer
// ----------------------------------------------------------------------------

// StartSpan returns the input context and a no-op Spanner
func (nt *logsOnlyTracer) StartSpan(ctx context.Context, operationName string, opts ...interface{}) (context.Context, tab.Spanner) {
return ctx, new(logsOnlySpanner)
}

// StartSpanWithRemoteParent returns the input context and a no-op Spanner
func (nt *logsOnlyTracer) StartSpanWithRemoteParent(ctx context.Context, operationName string, carrier tab.Carrier, opts ...interface{}) (context.Context, tab.Spanner) {
return ctx, new(logsOnlySpanner)
}

// FromContext returns a no-op Spanner without regard to the input context
func (nt *logsOnlyTracer) FromContext(ctx context.Context) tab.Spanner {
return new(logsOnlySpanner)
}

// NewContext returns the parent context
func (nt *logsOnlyTracer) NewContext(parent context.Context, span tab.Spanner) context.Context {
return parent
}

// ----------------------------------------------------------------------------
// Spanner
// ----------------------------------------------------------------------------

// logsOnlySpanner is a Spanner implementation that focuses
// on logging only.
type logsOnlySpanner struct{}

// AddAttributes is a no-op
func (ns *logsOnlySpanner) AddAttributes(attributes ...tab.Attribute) {}

// End is a no-op
func (ns *logsOnlySpanner) End() {}

// Logger returns a Logger implementation
func (ns *logsOnlySpanner) Logger() tab.Logger {
return &logpLogger{logp.L()}
}

// Inject is no-op
func (ns *logsOnlySpanner) Inject(carrier tab.Carrier) error {
return nil
}

// InternalSpan returns nil
func (ns *logsOnlySpanner) InternalSpan() interface{} {
return nil
}

// ----------------------------------------------------------------------------
// Logger
// ----------------------------------------------------------------------------

// logpLogger defers logging to the logp package
type logpLogger struct {
logger *logp.Logger
}

// Info logs a message at info level
func (sl logpLogger) Info(msg string, attributes ...tab.Attribute) {
sl.logger.Info(msg)
}

// Error logs a message at error level
func (sl logpLogger) Error(err error, attributes ...tab.Attribute) {
sl.logger.Error(err)
}

// Fatal logs a message at Fatal level
func (sl logpLogger) Fatal(msg string, attributes ...tab.Attribute) {
sl.logger.Fatal(msg)
}

// Debug logs a message at Debug level
func (sl logpLogger) Debug(msg string, attributes ...tab.Attribute) {
Comment on lines +100 to +115
Copy link
Member

Choose a reason for hiding this comment

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

[Blocker]

Why are the attributes ignored?
you could use the w functions to pass the attributes to logp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the current simple and log-focused logsOnlyTracer and logsOnlySpanner implementations, the attributes are nil:

CleanShot 2024-08-13 at 15 04 44@2x

I am targeting 8.15.1 to ship at least the logs because, as of today, we have literally zero visibility into the legacy SDK's inner workings. The logs would be pure gold in a couple of SDHs I am working on.

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 aim to bridge the legacy SDK logs into logp so they will be available in a diagnostics bundle.

I would love to have traces and spans. However, logs alone bring 80% of the value, and they seem achievable in the 8.15.1 FF time frame.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AndersonQ, do you think it's okay to ship this logging solution in time for 8.15.1 (this could help in troubleshooting a lot) and invest more in tracing for input v1 and v2 for 8.15.2 and 8.16?

Copy link
Member

Choose a reason for hiding this comment

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

well, something is better than nothing, even thought I still believe the effort to add the attributes is marginal, I won't block the PR.

Copy link
Member

Choose a reason for hiding this comment

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

but it'd appreciate a followup PR logging the attributes as well

sl.logger.Debug(msg)
}
Loading