Skip to content

Commit

Permalink
update java, go, nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Nov 21, 2024
1 parent c6a6e64 commit 76693e4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
34 changes: 15 additions & 19 deletions utils/build/docker/golang/parametric/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ type GetTraceConfigReturn struct {
}

type StartSpanArgs struct {
Name string `json:"name,omitempty"`
Service string `json:"service,omitempty"`
ParentId uint64 `json:"parent_id,omitempty"`
Resource string `json:"resource,omitempty"`
Type string `json:"type,omitempty"`
Origin string `json:"origin,omitempty"`
SpanTags []Tuple `json:"span_tags,omitempty"`
SpanLinks []SpanLink `json:"span_links,omitempty"`
Name string `json:"name,omitempty"`
Service string `json:"service,omitempty"`
ParentId uint64 `json:"parent_id,omitempty"`
Resource string `json:"resource,omitempty"`
Type string `json:"type,omitempty"`
SpanTags []Tuple `json:"span_tags,omitempty"`
SpanLinks []SpanLink `json:"span_links,omitempty"`
}

type Tuple []string

type SpanLink struct {
ParentId uint64 `json:"parent_id"`
Attributes AttributeKeyVals `json:"attributes,omitempty"`
ParentId uint64 `json:"parent_id"`
Attributes AttributeKeyVals `json:"attributes,omitempty"`
}

func (x Tuple) Key() string {
Expand Down Expand Up @@ -88,15 +87,12 @@ type SpanSetErrorArgs struct {
}

type OtelStartSpanArgs struct {
Name string `json:"name"`
ParentId uint64 `json:"parent_id"`
SpanKind uint64 `json:"span_kind"`
Service string `json:"service"`
Resource string `json:"resource"`
Type string `json:"type"`
Timestamp int64 `json:"timestamp"`
SpanLinks []SpanLink `json:"links"`
Attributes AttributeKeyVals `json:"attributes"`
Name string `json:"name"`
ParentId *uint64 `json:"parent_id"`
SpanKind *uint64 `json:"span_kind"`
Timestamp *int64 `json:"timestamp"`
SpanLinks []SpanLink `json:"links"`
Attributes AttributeKeyVals `json:"attributes"`
}

type OtelStartSpanReturn struct {
Expand Down
12 changes: 6 additions & 6 deletions utils/build/docker/golang/parametric/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ func (s *apmClientServer) OtelStartSpan(args OtelStartSpanArgs) (OtelStartSpanRe
}
var pCtx = context.Background()
var ddOpts []tracer.StartSpanOption
if pid := args.ParentId; pid != 0 {
parent, ok := s.otelSpans[pid]
if pid := args.ParentId; pid != nil {
parent, ok := s.otelSpans[*pid]
if ok {
pCtx = parent.ctx
}
}
var otelOpts []otel_trace.SpanStartOption
if args.SpanKind != 0 {
otelOpts = append(otelOpts, otel_trace.WithSpanKind(otel_trace.ValidateSpanKind(otel_trace.SpanKind(args.SpanKind))))
if args.SpanKind != nil {
otelOpts = append(otelOpts, otel_trace.WithSpanKind(otel_trace.ValidateSpanKind(otel_trace.SpanKind(*args.SpanKind - 1))))
}
if t := args.Timestamp; t != 0 {
tm := time.UnixMicro(t)
if t := args.Timestamp; t != nil {
tm := time.UnixMicro(*t)
otelOpts = append(otelOpts, otel_trace.WithTimestamp(tm))
}
if a := args.Attributes; len(a) > 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,21 @@ public StartSpanResult startSpan(@RequestBody StartSpanArgs args) {
// Build span from request
SpanBuilder builder = this.tracer.spanBuilder(args.name());
// Check parent span to create parent context from
if (args.parentId() != 0L) {
if (args.parentId() != null) {
Span parentSpan = getSpan(args.parentId());
if (parentSpan != null) {
Context contextWithParentSpan = parentSpan.storeInContext(Context.root());
builder.setParent(contextWithParentSpan);
}
}
// Add other span information
builder.setSpanKind(parseSpanKindNumber(args.spanKind()));
if (args.timestamp() > 0) {
if (args.spanKind() != null) {
builder.setSpanKind(parseSpanKindNumber(args.spanKind()));
}
if (args.timestamp() != null) {
builder.setStartTimestamp(args.timestamp(), MICROSECONDS);
}
if (args.links() != null && !args.links().isEmpty()) {
if (!args.links().isEmpty()) {
for (SpanLink spanLink : args.links()) {
LOGGER.debug("Span link: {}", spanLink);
Span span = getSpan(spanLink.parentId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import java.util.Map;

public record StartSpanArgs(
@JsonProperty("parent_id") long parentId,
@JsonProperty("parent_id") Long parentId,
String name,
@JsonProperty("span_kind") int spanKind,
long timestamp,
@JsonProperty("span_kind") Integer spanKind,
Long timestamp,
List<SpanLink> links,
Map<String, Object> attributes) {
}
6 changes: 5 additions & 1 deletion utils/build/docker/nodejs/parametric/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,13 @@ app.post('/trace/otel/start_span', (req, res) => {
return {context: spanContext, attributes: link.attributes}
});

let kind = null
if (request.kind != null) {
kind = request.kind - 1
}
const span = otelTracer.startSpan(request.name, {
type: request.type,
kind: request.kind,
kind: kind,
attributes: request.attributes,
links,
startTime: microLongToHrTime(request.timestamp)
Expand Down

0 comments on commit 76693e4

Please sign in to comment.