Skip to content

Commit d504bd1

Browse files
authored
Merge pull request #163 from abicky/integrate-with-opentelemetry-logs
Integrate with OpenTelemetry logs
2 parents 8317760 + 8bc2370 commit d504bd1

File tree

13 files changed

+224
-268
lines changed

13 files changed

+224
-268
lines changed

chains/tendermint/chain.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (c *Chain) sendMsgs(ctx context.Context, msgs []sdk.Msg) (*sdk.TxResponse,
199199
// call msgEventListener if needed
200200
if c.msgEventListener != nil {
201201
if err := c.msgEventListener.OnSentMsg(ctx, msgs); err != nil {
202-
logger.Error("failed to OnSendMsg call", err)
202+
logger.ErrorContext(ctx, "failed to OnSendMsg call", err)
203203
return res, nil
204204
}
205205
}
@@ -269,12 +269,12 @@ func (c *Chain) rawSendMsgs(ctx context.Context, msgs []sdk.Msg) (*sdk.TxRespons
269269
// transaction was successfully executed.
270270
if res.Code != 0 {
271271
span.SetStatus(codes.Error, "non-zero response code")
272-
c.LogFailedTx(res, err, msgs)
272+
c.LogFailedTx(ctx, res, err, msgs)
273273
return res, false, nil
274274
}
275275

276276
span.SetAttributes(semconv.TxHashKey.String(res.TxHash))
277-
c.LogSuccessTx(res, msgs)
277+
c.LogSuccessTx(ctx, res, msgs)
278278
return res, true, nil
279279
}
280280

chains/tendermint/log-chain.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tendermint
22

33
import (
4+
"context"
45
"fmt"
56
"strings"
67

@@ -9,36 +10,36 @@ import (
910
)
1011

1112
// LogFailedTx takes the transaction and the messages to create it and logs the appropriate data
12-
func (c *Chain) LogFailedTx(res *sdk.TxResponse, err error, msgs []sdk.Msg) {
13+
func (c *Chain) LogFailedTx(ctx context.Context, res *sdk.TxResponse, err error, msgs []sdk.Msg) {
1314
logger := GetChainLogger()
1415
if c.debug {
15-
logger.Info("sending-tx", "chain-id", c.ChainID())
16+
logger.InfoContext(ctx, "sending-tx", "chain-id", c.ChainID())
1617
for _, msg := range msgs {
1718
c.Print(msg, false, false)
1819
}
1920
}
2021

2122
if err != nil {
22-
logger.Error("failed-tx", err, "chain-id", c.ChainID())
23+
logger.ErrorContext(ctx, "failed-tx", err, "chain-id", c.ChainID())
2324
if res == nil {
2425
return
2526
}
2627
}
2728

2829
if res.Code != 0 && res.Codespace != "" {
29-
logger.Info("res", "chain-id", c.ChainID(), "height", res.Height, "action", getMsgAction(msgs), "codespace", res.Codespace, "code", res.Code, "raw-log", res.RawLog)
30+
logger.InfoContext(ctx, "res", "chain-id", c.ChainID(), "height", res.Height, "action", getMsgAction(msgs), "codespace", res.Codespace, "code", res.Code, "raw-log", res.RawLog)
3031
}
3132

3233
if c.debug && !res.Empty() {
33-
logger.Info("tx-response", "chain-id", c.ChainID(), "res", res)
34+
logger.InfoContext(ctx, "tx-response", "chain-id", c.ChainID(), "res", res)
3435
c.Print(res, false, false)
3536
}
3637
}
3738

3839
// LogSuccessTx take the transaction and the messages to create it and logs the appropriate data
39-
func (c *Chain) LogSuccessTx(res *sdk.TxResponse, msgs []sdk.Msg) {
40+
func (c *Chain) LogSuccessTx(ctx context.Context, res *sdk.TxResponse, msgs []sdk.Msg) {
4041
logger := GetChainLogger()
41-
logger.Info("success-tx", "chain-id", c.ChainID(), "height", res.Height, "hash", res.TxHash)
42+
logger.InfoContext(ctx, "success-tx", "chain-id", c.ChainID(), "height", res.Height, "hash", res.TxHash)
4243
}
4344

4445
// Print fmt.Printlns the json or yaml representation of whatever is passed in

0 commit comments

Comments
 (0)