Skip to content

Commit

Permalink
implemented simple event API
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlobaron committed Apr 25, 2017
1 parent 78b5bce commit 3250052
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The Instana tracer will remap OpenTracing HTTP headers into Instana Headers, so

Following examples are included in the `examples` folder:

* **simple** - demoes generally how to use the tracer
* **http** - demoes how http server and client should be instrumented
* **rpc** - demoes the fallback to RPC
* **ot-simple/simple.go** - demoes generally how to use the tracer
* **webserver/http.go** - demoes how http server and client should be instrumented
* **rpc/rpc.go** - demoes the fallback to RPC
* **event/event.go** - demoes the event API
1 change: 1 addition & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
AgentDiscoveryURL = "/com.instana.plugin.golang.discovery"
AgentTracesURL = "/com.instana.plugin.golang/traces."
AgentDataURL = "/com.instana.plugin.golang."
AgentEventURL = "/com.instana.plugin.generic.event"
AgentDefaultHost = "localhost"
AgentDefaultPort = 42699
AgentHeader = "Instana Agent"
Expand Down
47 changes: 47 additions & 0 deletions event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package instana

type EventData struct {
Title string `json:"title"`
Text string `json:"text"`
Duration int `json:"duration"`
Severity int `json:"severity"`
Plugin string `json:"plugin,omitempty"`
ID string `json:"id,omitempty"`
Host string `json:"host,omitempty"`
}

const (
ServicePlugin = "com.instana.forge.connection.http.logical.LogicalWebApp"
ServiceHost = ""
)

func SendDefaultServiceEvent(title string, text string, severity int) {
SendServiceEvent(sensor.serviceName, title, text, severity)
}

func SendServiceEvent(service string, title string, text string, severity int) {
sendEvent(&EventData{
Title: title,
Text: text,
Duration: 0,
Severity: severity,
Plugin: ServicePlugin,
ID: service,
Host: ServiceHost})
}

func SendHostEvent(title string, text string, severity int) {
sendEvent(&EventData{
Title: title,
Text: text,
Duration: 0,
Severity: severity})
}

func sendEvent(event *EventData) {

log.debug(event)

//we do fire & forget here, because the whole pid dance isn't necessary to send events
go sensor.agent.request(sensor.agent.makeURL(AgentEventURL), "POST", event)
}
27 changes: 27 additions & 0 deletions example/event/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"time"

"github.com/instana/golang-sensor"
)

const (
service = "golang-event"
)

func main() {
instana.InitSensor(&instana.Options{
Service: service,
LogLevel: instana.Debug})

go forever()
select {}
}

func forever() {
for {
instana.SendDefaultServiceEvent("Event from the Golang sample", "{field: data}", -1)
time.Sleep(5000 * time.Millisecond)
}
}

0 comments on commit 3250052

Please sign in to comment.