#!/usr/bin/python

# Twisted imports
from twisted.internet import reactor

# Appdash imports
import appdash

# Create a remote appdash collector.
collector = appdash.RemoteCollectorFactory(reactor, debug=True)

# Create a trace.
trace = appdash.SpanID(root=True)

# Generate a few spans with some annotations.
span = trace
for i in range(0, 7):
    # Collect some annotations.
    a1 = appdash.Annotation(
        key="HTTPClient",
        value="/foo/bar?eq=1",
    )
    a2 = appdash.Annotation(
        key="SQL",
        value="select * from table;",
    )
    collector.collect(span, a1, a2)

    # Create a new child span whose parent is the last span we created.
    span = appdash.SpanID(parent=span)

# Have Twisted perform the connection and run.
reactor.connectTCP("", 7701, collector)
reactor.run()

#!/usr/bin/python

# Imports
from twisted.internet import reactor
import time
import appdash

# Create a remote appdash collector.
collector = appdash.RemoteCollectorFactory(reactor, debug=True)

# Create a trace.
trace = appdash.SpanID(root=True)

# Generate a few spans with some annotations.
span = trace
for i in range(0, 7):
    # Name the span.
    if i == 0:
        collector.collect(span, *appdash.MarshalEvent(appdash.SpanNameEvent("Request")))
    else:
        collector.collect(span, *appdash.MarshalEvent(appdash.SpanNameEvent("SQL Query")))

    # Marshal some events into annotations and collect them.
    sendTime = time.time()
    recvTime = sendTime + 2
    collector.collect(span, *appdash.MarshalEvent(appdash.SQLEvent(
        "SELECT * FROM table_name;",
        sendTime,
        recv = recvTime, # optional: default is current time.
        tag = "foobar",  # optional: user-specific tag, useful for e.g. filtering.
    )))

    if i % 2 == 0:
        collector.collect(span, *appdash.MarshalEvent(appdash.LogEvent("Hello world!")))

    # Create a new child span whose parent is the last span we created.
    span = appdash.SpanID(parent=span)

# Have Twisted perform the connection and run.
reactor.connectTCP("", 7701, collector)
reactor.run()

make the example generate proper events.