Skip to content

Commit

Permalink
Separate "span" into its own package (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
roncohen authored Jul 18, 2018
1 parent 3daa4fe commit 3897a91
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 79 deletions.
2 changes: 1 addition & 1 deletion include/fields.go

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

59 changes: 59 additions & 0 deletions model/span/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
- key: apm-span
title: APM Span
description: Span-specific data for APM.
fields:
- name: view spans
format: url
label_template: "View Spans"

- name: span
type: group
dynamic: false
fields:

- name: id
type: long
description: >
A locally unique ID of the span.
- name: name
type: keyword
count: 1
description: >
Generic designation of a span in the scope of a transaction.
- name: type
type: keyword
count: 1
description: >
Keyword of specific relevance in the service's domain (eg: 'db.postgresql.query', 'template.erb', 'cache', etc).
- name: start
type: group
description:
fields:
- name: us
type: long
count: 1
description: >
Offset relative to the transaction's timestamp identifying the start of the span, in microseconds.
- name: duration
type: group
description:
fields:

- name: us
type: long
count: 1
description: >
Duration of the span, in microseconds.
format: duration
input_format: microseconds
output_format: asMilliseconds
output_precision: 0

- name: parent
type: long
description: >
The locally unique ID of the parent of the span.
2 changes: 1 addition & 1 deletion model/transaction/span.go → model/span/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package transaction
package span

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package transaction
package span

import (
m "github.com/elastic/apm-server/model"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package transaction
package span

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion model/transaction/span_test.go → model/span/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package transaction
package span

import (
"errors"
Expand Down
61 changes: 0 additions & 61 deletions model/transaction/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,64 +64,3 @@
- name: total
type: long
description: The total amount of dropped spans for this transaction.


- key: apm-span
title: APM Span
description: Span-specific data for APM.
fields:
- name: view spans
format: url
label_template: "View Spans"

- name: span
type: group
dynamic: false
fields:

- name: id
type: long
description: >
A locally unique ID of the span.
- name: name
type: keyword
count: 1
description: >
Generic designation of a span in the scope of a transaction.
- name: type
type: keyword
count: 1
description: >
Keyword of specific relevance in the service's domain (eg: 'db.postgresql.query', 'template.erb', 'cache', etc).
- name: start
type: group
description:
fields:
- name: us
type: long
count: 1
description: >
Offset relative to the transaction's timestamp identifying the start of the span, in microseconds.
- name: duration
type: group
description:
fields:

- name: us
type: long
count: 1
description: >
Duration of the span, in microseconds.
format: duration
input_format: microseconds
output_format: asMilliseconds
output_precision: 0

- name: parent
type: long
description: >
The locally unique ID of the parent of the span.
13 changes: 7 additions & 6 deletions model/transaction/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"time"

"github.com/elastic/apm-server/model/span"
"github.com/elastic/apm-server/utility"
"github.com/elastic/beats/libbeat/common"
)
Expand All @@ -36,7 +37,7 @@ type Event struct {
Marks common.MapStr
Sampled *bool
SpanCount SpanCount
Spans []*Span
Spans []*span.Span
}
type SpanCount struct {
Dropped Dropped
Expand Down Expand Up @@ -67,12 +68,12 @@ func DecodeEvent(input interface{}, err error) (*Event, error) {
SpanCount: SpanCount{Dropped: Dropped{Total: decoder.IntPtr(raw, "total", "span_count", "dropped")}},
}
err = decoder.Err
var span *Span
var sp *span.Span
spans := decoder.InterfaceArr(raw, "spans")
e.Spans = make([]*Span, len(spans))
for idx, sp := range spans {
span, err = DecodeSpan(sp, err)
e.Spans[idx] = span
e.Spans = make([]*span.Span, len(spans))
for idx, rawSpan := range spans {
sp, err = span.DecodeSpan(rawSpan, err)
e.Spans[idx] = sp
}
return &e, err
}
Expand Down
9 changes: 5 additions & 4 deletions model/transaction/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"time"

"github.com/elastic/apm-server/model/span"
"github.com/elastic/beats/libbeat/common"
)

Expand Down Expand Up @@ -60,7 +61,7 @@ func TestTransactionEventDecode(t *testing.T) {
Duration: 0.0, Timestamp: time.Time{},
Context: nil, Marks: nil, Sampled: nil,
SpanCount: SpanCount{Dropped: Dropped{Total: nil}},
Spans: []*Span{},
Spans: []*span.Span{},
},
},
{
Expand All @@ -81,8 +82,8 @@ func TestTransactionEventDecode(t *testing.T) {
Duration: duration, Timestamp: timestampParsed,
Context: context, Marks: marks, Sampled: &sampled,
SpanCount: SpanCount{Dropped: Dropped{Total: &dropped}},
Spans: []*Span{
&Span{Name: "span", Type: "db", Start: 1.2, Duration: 2.3},
Spans: []*span.Span{
&span.Span{Name: "span", Type: "db", Start: 1.2, Duration: 2.3},
},
},
},
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestEventTransform(t *testing.T) {
Timestamp: time.Now(),
Duration: 65.98,
Context: common.MapStr{"foo": "bar"},
Spans: []*Span{},
Spans: []*span.Span{},
Sampled: &sampled,
SpanCount: SpanCount{Dropped: Dropped{Total: &dropped}},
},
Expand Down
3 changes: 2 additions & 1 deletion model/transaction/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/elastic/apm-server/config"
"github.com/elastic/apm-server/model"
m "github.com/elastic/apm-server/model"
"github.com/elastic/apm-server/model/span"
"github.com/elastic/apm-server/model/transaction/generated/schema"
"github.com/elastic/apm-server/utility"
"github.com/elastic/apm-server/validation"
Expand Down Expand Up @@ -99,7 +100,7 @@ func (pa *Payload) Transform(conf config.Config) []beat.Event {
logp.NewLogger("transaction").Debugf("Transform transaction events: events=%d, service=%s, agent=%s:%s", len(pa.Events), pa.Service.Name, pa.Service.Agent.Name, pa.Service.Agent.Version)

context := m.NewContext(&pa.Service, pa.Process, pa.System, pa.User)
spanContext := NewSpanContext(&pa.Service)
spanContext := span.NewSpanContext(&pa.Service)

var events []beat.Event
for idx := 0; idx < len(pa.Events); idx++ {
Expand Down
5 changes: 3 additions & 2 deletions model/transaction/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/elastic/apm-server/config"
m "github.com/elastic/apm-server/model"
"github.com/elastic/apm-server/model/span"
"github.com/elastic/beats/libbeat/common"
)

Expand Down Expand Up @@ -95,7 +96,7 @@ func TestPayloadDecode(t *testing.T) {
Type: "transaction",
Timestamp: timestampParsed,
Duration: 34.9,
Spans: []*Span{},
Spans: []*span.Span{},
},
},
},
Expand Down Expand Up @@ -188,7 +189,7 @@ func TestPayloadTransform(t *testing.T) {
},
},
}
spans := []*Span{{}}
spans := []*span.Span{{}}
txValidWithSpan := Event{Timestamp: timestamp, Spans: spans}
spanEs := common.MapStr{
"context": common.MapStr{
Expand Down
1 change: 1 addition & 0 deletions processor/transaction/package_tests/attrs_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func procSetup() *tests.ProcessorSetup {
Proc: transaction.Processor,
FullPayloadPath: "../testdata/transaction/payload.json",
TemplatePaths: []string{"../../../model/transaction/_meta/fields.yml",
"../../../model/span/_meta/fields.yml",
"../../../_meta/fields.common.yml"},
Schema: schema.PayloadSchema,
}
Expand Down

0 comments on commit 3897a91

Please sign in to comment.