Comments (12)
@iamemilio working as expected, you are correct!
let's get this in the docs asap! whoever comes next will probably have it way better than me.
thanks a ton for this help.
from go-agent.
Ah! I know whats happening. Are you waiting for your application to connect to new relic? If not, then its attempting to capture the logs, but failing. We insert our instrumentation into the zapcore object, and anytime a zap process invokes the Write() method, we capture the log in the agent, even if its not synced/flushed yet. But if the agent has not completed its connection handshake, it may drop the logs.
quick fix:
if err := app.WaitForConnection(5 * time.Second); nil != err {
fmt.Println(err)
}
from go-agent.
@iamemilio this looks very promising, let me try this and get back to you. Can't thank you enough for this! Opening the gates of hope
from go-agent.
my actual code, and this isn't working:
func Logger(app *newrelic.Application) (*zap.Logger, *zapcore.Core, error) {
core := zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(os.Stdout), zap.InfoLevel)
backgroundCore, err := nrzap.WrapBackgroundCore(core, app)
if err != nil && err != nrzap.ErrNilApp {
panic(err)
}
l, err := zap.New(backgroundCore), nil
// todo where is this message?
l.Info("background logs are working")
return l, &core, err
}
but here, the messages arrive
txn := newrelic.FromContext(ctx)
if txn == nil {
txn = app.StartTransaction(req.Spec().Procedure)
} else {
txn.SetName(req.Spec().Procedure)
}
txnCore, err := nrzap.WrapTransactionCore(*core, txn)
if err != nil && err != nrzap.ErrNilTxn {
panic(err)
}
txnLogger := zap.New(txnCore)
intermittently I see 1 single message from the original backgroundLogger
from go-agent.
- this may be connected to
.Sugar()
where anything from aSugared
logger is not in new relic - log messages in new relic are missing a lot of the json i am sending, i'm looking for any docs on that
from go-agent.
hmm, let me take a look at this and dig into it a bit. Thanks for reporting!
from go-agent.
So, I built this reproducer based on your code:
func TestBackgroundLoggerSugared(t *testing.T) {
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
newrelic.ConfigAppLogDecoratingEnabled(true),
newrelic.ConfigAppLogForwardingEnabled(true),
)
core := zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(os.Stdout), zap.InfoLevel)
backgroundCore, err := WrapBackgroundCore(core, app.Application)
if err != nil && err != ErrNilApp {
t.Fatal(err)
}
logger := zap.New(backgroundCore).Sugar()
err = errors.New("this is a test error")
msg := "this is a test error message"
// for background logging:
logger.Error(msg, zap.Error(err), zap.String("test-key", "test-val"))
logger.Sync()
app.ExpectLogEvents(t, []internal.WantLog{
{
Severity: zap.ErrorLevel.String(),
Message: msg,
Timestamp: internal.MatchAnyUnixMilli,
},
})
}
Output:
{"level":"error","ts":1709919339.6399841,"msg":"this is a test error message{error 26 0 this is a test error} {test-key 15 0 test-val <nil>}"}
I do see that in my test function, this log message gets captured by the agent.
got: "this is a test error message{error 26 0 this is a test error} {test-key 15 0 test-val <nil>}"
I am wondering if maybe I am missing something? Could you provide any corrections for the test that you think would cause the error to occur?
from go-agent.
from go-agent.
I don't know I'll have to check out what a possible difference might be.
There's probably more factors to consider on my end.
from go-agent.
But that first message in my example does not arrive and neither do any from the background logger
from go-agent.
Is it possible it has to do with the logger syncing? Because I even sync it at some point in the startup code (before the tx takes over for requests)
from go-agent.
hmm, yeah possibly. I don't really have a good idea of how the zap logging buffer gets written, but in the example code I ran I force the buffer to flush by calling Sync(), and that seemed to guarantee capture and writes of those logs.
from go-agent.
Related Issues (20)
- Consumes a lot of memory during large body size requests HOT 2
- External Services(AWS sdk go v2 ) api calls are not logged / visible when using github.com/newrelic/go-agent/v3/integrations/nrawssdk-v HOT 3
- Remove fasthttp dependency from main module HOT 2
- Update google.golang.org/grpc from 1.54.0 to 1.56.3 HOT 2
- transaction.go reqBody(req *http.Request) turn nil body into non Nil body for request.Body == http.NoBody HOT 1
- Add support to CopyFrom method in pgx integration HOT 1
- fmt.Stringer support for user attributes (especially for SQL query parameters)
- UNKNOWN log levels when using the native log package HOT 2
- `.Ignore()` not ignoring transaction (go-agent + nrgin) HOT 6
- Integration for gqlgen HOT 2
- nrpgx5 data-race HOT 5
- Changelog Go agent EOL Policy link is broken HOT 1
- agent with nrzap is not forwarding logs to newrelic HOT 3
- zap logger.With log message properties are not sent to new relic HOT 4
- Attributes are not forwarded to NewRelic for logs HOT 16
- go agent , but not see span, please help me ,thanks HOT 3
- Specify service version during initial newrelic configuration HOT 6
- Possible memory leak in Go agent HOT 11
- How to use AWS Lambda Web Adapter in golang app
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-agent.