add more span tags
This commit is contained in:
parent
63829e7e07
commit
1a14621969
5 changed files with 32 additions and 17 deletions
|
|
@ -93,6 +93,8 @@ type item struct {
|
||||||
func (c *Checkpoint) Get(ctx context.Context, streamName, shardID string) (string, error) {
|
func (c *Checkpoint) Get(ctx context.Context, streamName, shardID string) (string, error) {
|
||||||
namespace := fmt.Sprintf("%s-%s", c.appName, streamName)
|
namespace := fmt.Sprintf("%s-%s", c.appName, streamName)
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "checkpoint.ddb.Get",
|
span, ctx := opentracing.StartSpanFromContext(ctx, "checkpoint.ddb.Get",
|
||||||
|
opentracing.Tag{Key: "appName", Value: c.appName},
|
||||||
|
opentracing.Tag{Key: "tableName", Value: c.tableName},
|
||||||
opentracing.Tag{Key: "namespace", Value: namespace},
|
opentracing.Tag{Key: "namespace", Value: namespace},
|
||||||
opentracing.Tag{Key: "shardID", Value: shardID},
|
opentracing.Tag{Key: "shardID", Value: shardID},
|
||||||
)
|
)
|
||||||
|
|
@ -131,6 +133,8 @@ func (c *Checkpoint) Set(ctx context.Context, streamName, shardID, sequenceNumbe
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "checkpoint.ddb.Set",
|
span, ctx := opentracing.StartSpanFromContext(ctx, "checkpoint.ddb.Set",
|
||||||
|
opentracing.Tag{Key: "appName", Value: c.appName},
|
||||||
|
opentracing.Tag{Key: "tableName", Value: c.tableName},
|
||||||
opentracing.Tag{Key: "stream.name", Value: streamName},
|
opentracing.Tag{Key: "stream.name", Value: streamName},
|
||||||
opentracing.Tag{Key: "shardID", Value: shardID},
|
opentracing.Tag{Key: "shardID", Value: shardID},
|
||||||
)
|
)
|
||||||
|
|
@ -174,6 +178,8 @@ func (c *Checkpoint) save(ctx context.Context) error {
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "checkpoint.ddb.save")
|
span, ctx := opentracing.StartSpanFromContext(ctx, "checkpoint.ddb.save")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
span = span.SetTag("appName", c.appName)
|
||||||
|
span = span.SetTag("tableName", c.tableName)
|
||||||
|
|
||||||
for key, sequenceNumber := range c.checkpoints {
|
for key, sequenceNumber := range c.checkpoints {
|
||||||
item, err := dynamodbattribute.MarshalMap(item{
|
item, err := dynamodbattribute.MarshalMap(item{
|
||||||
|
|
|
||||||
27
consumer.go
27
consumer.go
|
|
@ -103,7 +103,7 @@ type Consumer struct {
|
||||||
|
|
||||||
// Scan scans each of the shards of the stream, calls the callback
|
// Scan scans each of the shards of the stream, calls the callback
|
||||||
// func with each of the kinesis records.
|
// func with each of the kinesis records.
|
||||||
func (c *Consumer) Scan(ctx context.Context, fn func(*Record) ScanStatus) error {
|
func (c *Consumer) Scan(ctx context.Context, fn func(context.Context, *Record) ScanStatus) error {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ func (c *Consumer) Scan(ctx context.Context, fn func(*Record) ScanStatus) error
|
||||||
func (c *Consumer) ScanShard(
|
func (c *Consumer) ScanShard(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
shardID string,
|
shardID string,
|
||||||
fn func(*Record) ScanStatus,
|
fn func(context.Context, *Record) ScanStatus,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "consumer.scanshard")
|
span, ctx := opentracing.StartSpanFromContext(ctx, "consumer.scanshard")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|
@ -184,12 +184,12 @@ func (c *Consumer) ScanShard(
|
||||||
return fmt.Errorf("get shard iterator error: %v", err)
|
return fmt.Errorf("get shard iterator error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.logger.Log("scanning", shardID, lastSeqNum)
|
c.logger.Log(fmt.Sprintf("scanning shardID %s lastSeqNum %s", shardID, lastSeqNum))
|
||||||
|
|
||||||
return c.scanPagesOfShard(ctx, shardID, lastSeqNum, shardIterator, fn)
|
return c.scanPagesOfShard(ctx, shardID, lastSeqNum, shardIterator, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Consumer) scanPagesOfShard(ctx context.Context, shardID, lastSeqNum string, shardIterator *string, fn func(*Record) ScanStatus) error {
|
func (c *Consumer) scanPagesOfShard(ctx context.Context, shardID, lastSeqNum string, shardIterator *string, fn func(context.Context, *Record) ScanStatus) error {
|
||||||
span := opentracing.SpanFromContext(ctx)
|
span := opentracing.SpanFromContext(ctx)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
@ -241,10 +241,10 @@ func isShardClosed(nextShardIterator, currentShardIterator *string) bool {
|
||||||
return nextShardIterator == nil || currentShardIterator == nextShardIterator
|
return nextShardIterator == nil || currentShardIterator == nextShardIterator
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Consumer) handleRecord(ctx context.Context, shardID string, r *Record, fn func(*Record) ScanStatus) (isScanStopped bool, err error) {
|
func (c *Consumer) handleRecord(ctx context.Context, shardID string, r *Record, fn func(context.Context, *Record) ScanStatus) (isScanStopped bool, err error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "consumer.handleRecord")
|
span, ctx := opentracing.StartSpanFromContext(ctx, "consumer.handleRecord")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
status := fn(r)
|
status := fn(ctx, r)
|
||||||
if !status.SkipCheckpoint {
|
if !status.SkipCheckpoint {
|
||||||
span.LogKV("scan.state", status)
|
span.LogKV("scan.state", status)
|
||||||
if err := c.checkpoint.Set(ctx, c.streamName, shardID, *r.SequenceNumber); err != nil {
|
if err := c.checkpoint.Set(ctx, c.streamName, shardID, *r.SequenceNumber); err != nil {
|
||||||
|
|
@ -272,6 +272,7 @@ func (c *Consumer) handleRecord(ctx context.Context, shardID string, r *Record,
|
||||||
func (c *Consumer) getShardIDs(ctx context.Context, streamName string) ([]string, error) {
|
func (c *Consumer) getShardIDs(ctx context.Context, streamName string) ([]string, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "consumer.getShardIDs")
|
span, ctx := opentracing.StartSpanFromContext(ctx, "consumer.getShardIDs")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
span = span.SetTag("streamName", streamName)
|
||||||
|
|
||||||
resp, err := c.client.DescribeStreamWithContext(ctx,
|
resp, err := c.client.DescribeStreamWithContext(ctx,
|
||||||
&kinesis.DescribeStreamInput{
|
&kinesis.DescribeStreamInput{
|
||||||
|
|
@ -293,14 +294,20 @@ func (c *Consumer) getShardIDs(ctx context.Context, streamName string) ([]string
|
||||||
|
|
||||||
func (c *Consumer) getShardIterator(ctx context.Context, streamName, shardID, lastSeqNum string) (*string, error) {
|
func (c *Consumer) getShardIterator(ctx context.Context, streamName, shardID, lastSeqNum string) (*string, error) {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "consumer.getShardIterator",
|
span, ctx := opentracing.StartSpanFromContext(ctx, "consumer.getShardIterator",
|
||||||
opentracing.Tag{Key: "lastSeqNum", Value: "lastSeqNum"})
|
opentracing.Tag{Key: "streamName", Value: streamName},
|
||||||
|
opentracing.Tag{Key: "shardID", Value: shardID},
|
||||||
|
opentracing.Tag{Key: "lastSeqNum", Value: lastSeqNum})
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
shard := aws.String(shardID)
|
||||||
|
stream := aws.String(streamName)
|
||||||
params := &kinesis.GetShardIteratorInput{
|
params := &kinesis.GetShardIteratorInput{
|
||||||
ShardId: aws.String(shardID),
|
ShardId: shard,
|
||||||
StreamName: aws.String(streamName),
|
StreamName: stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span = span.SetTag("shardID", shard)
|
||||||
|
span = span.SetTag("streamName", stream)
|
||||||
|
|
||||||
if lastSeqNum != "" {
|
if lastSeqNum != "" {
|
||||||
params.ShardIteratorType = aws.String("AFTER_SEQUENCE_NUMBER")
|
params.ShardIteratorType = aws.String("AFTER_SEQUENCE_NUMBER")
|
||||||
params.StartingSequenceNumber = aws.String(lastSeqNum)
|
params.StartingSequenceNumber = aws.String(lastSeqNum)
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
ctx := context.Background()
|
||||||
log := utility.NewLogger(serviceName, alog.DebugLevel)
|
log := utility.NewLogger(serviceName, alog.DebugLevel)
|
||||||
tracer, closer := utility.NewTracer(serviceName)
|
tracer, closer := utility.NewTracer(serviceName)
|
||||||
defer closer.Close()
|
defer closer.Close()
|
||||||
|
|
@ -52,9 +53,9 @@ func main() {
|
||||||
table := flag.String("table", "", "Checkpoint table name")
|
table := flag.String("table", "", "Checkpoint table name")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
span.SetTag("app.name", app)
|
span.SetBaggageItem("app.name", *app)
|
||||||
span.SetTag("stream.name", stream)
|
span.SetBaggageItem("stream.name", *stream)
|
||||||
span.SetTag("table.name", table)
|
span.SetBaggageItem("table.name", *table)
|
||||||
|
|
||||||
fmt.Println("set tag....")
|
fmt.Println("set tag....")
|
||||||
|
|
||||||
|
|
@ -67,7 +68,7 @@ func main() {
|
||||||
myDynamoDbClient := dynamodb.New(sess)
|
myDynamoDbClient := dynamodb.New(sess)
|
||||||
|
|
||||||
// ddb checkpoint
|
// ddb checkpoint
|
||||||
ctx := opentracing.ContextWithSpan(context.Background(), span)
|
ctx = opentracing.ContextWithSpan(ctx, span)
|
||||||
retryer := utility.NewRetryer()
|
retryer := utility.NewRetryer()
|
||||||
ck, err := checkpoint.New(ctx, *app, *table, checkpoint.WithDynamoClient(myDynamoDbClient), checkpoint.WithRetryer(retryer))
|
ck, err := checkpoint.New(ctx, *app, *table, checkpoint.WithDynamoClient(myDynamoDbClient), checkpoint.WithRetryer(retryer))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -113,7 +114,9 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// scan stream
|
// scan stream
|
||||||
err = c.Scan(ctx, func(r *consumer.Record) consumer.ScanStatus {
|
err = c.Scan(ctx, func(ctx context.Context, r *consumer.Record) consumer.ScanStatus {
|
||||||
|
span, _ := opentracing.StartSpanFromContext(ctx, "consumer.processRecord")
|
||||||
|
defer span.Finish()
|
||||||
fmt.Println(string(r.Data))
|
fmt.Println(string(r.Data))
|
||||||
// continue scanning
|
// continue scanning
|
||||||
return consumer.ScanStatus{}
|
return consumer.ScanStatus{}
|
||||||
|
|
|
||||||
BIN
examples/distributed-tracing/producer.png
Normal file
BIN
examples/distributed-tracing/producer.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 539 KiB |
|
|
@ -43,8 +43,7 @@ func main() {
|
||||||
|
|
||||||
var streamName = flag.String("stream", "", "Stream name")
|
var streamName = flag.String("stream", "", "Stream name")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
span.SetBaggageItem("producer.stream.name", *streamName)
|
||||||
span.SetTag("producer.stream.name", streamName)
|
|
||||||
|
|
||||||
// download file with test data
|
// download file with test data
|
||||||
// curl https://s3.amazonaws.com/kinesis.test/users.txt -o /tmp/users.txt
|
// curl https://s3.amazonaws.com/kinesis.test/users.txt -o /tmp/users.txt
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue