For some inexplicable reason, google provides no stackdriver api for appengine, so I'm stuck implementing one. No worries - I thought - I have already worked with the API builder to talk to bigquery, so I built up a client and started trying to send events:
credentials = SignedJwtAssertionCredentials(STACKDRIVER_AUTH_GOOGLE_CLIENT_EMAIL,
STACKDRIVER_AUTH_GOOGLE_PRIVATE_KEY,
scope='https://www.googleapis.com/auth/trace.append')
http = httplib2.Http()
credentials.refresh(http) #Working around an oauth2client bug
credentials = credentials.authorize(http)
service = build('cloudtrace', 'v1', http=http)
batch = service.new_batch_http_request()
batch.add(service.projects().patchTraces(
body=traces_json,
projectId=STACKDRIVER_AUTH_GOOGLE_PROJECT_ID))
print batch.execute()
I left out the definition of traces_json because no matter what I send, the service always responds with an error. If traces_json = '{}':
{u'error': {u'code': 400,
u'errors': [{u'domain': u'global',
u'message': u'Invalid value at \'traces\' (type.googleapis.com/google.devtools.cloudtrace.v1.Traces), "{}"',
u'reason': u'badRequest'}],
u'message': u'Invalid value at \'traces\' (type.googleapis.com/google.devtools.cloudtrace.v1.Traces), "{}"',
u'status': u'INVALID_ARGUMENT'}}
But even if I use a body, crafted from the google documentation, I still get the same error.
I'm running a packet sniffer on the machine where I'm attempting this, and only very rarely see it actually communicating with googleapis.com.
So the question is, really, what am I missing that will get me sending events to stackdriver?
UPDATE
Here's the most recent iteration of what I'd been working with, though using the google doc example verbatim (with the exception of changing the project id) produces the same result.
{
"traces": [
{
"projectId": "projectname",
"traceId": "1234123412341234aaaabb3412347890",
"spans": [
{
"kind": "RPC_SERVER",
"name": "trace_name",
"labels": {"label1": "value1", "label2": "value2"},
"spanId": "spanId1",
"startTime": "2016-06-01T05:01:23.045123456Z",
"endTime": "2016-06-01T05:01:23.945123456Z",
},
],
},
],
}
And the error message that comes with it:
{u'error': {u'code': 400,
u'errors': [{u'domain': u'global',
u'message': u'Invalid value at \'traces\' (type.googleapis.com/google.devtools.cloudtrace.v1.Traces), "MY ENTIRE JSON IS REPEATED HERE"',
u'reason': u'badRequest'}],
u'message': u'Invalid value at \'traces\' (type.googleapis.com/google.devtools.cloudtrace.v1.Traces), "MY ENTIRE JSON IS REPEATED HERE"',
u'status': u'INVALID_ARGUMENT'}}
SECOND UPDATE
Doing this in the explorer produces approximately the same result. I had to switch to a numeric span_id because, despite the docs' statement that it only has to be a unique string, I get errors about requiring what appears to be a 64-bit integer, any time I provide anything else.
PATCH https://cloudtrace.googleapis.com/v1/projects/[number or name]/traces?key={YOUR_API_KEY}
{
"traces": [
{
"projectId": "[number or name]",
"traceId": "1234123412341234aaaabb3412347891",
"spans": [
{
"kind": "RPC_SERVER",
"name": "trace_name",
"labels": {
"label1": "value1"
},
"startTime": "2016-06-01T05:01:23.045123456Z",
"endTime": "2016-06-01T05:01:25.045123456Z"
},
{
"spanId": "0"
}
]
}
]
}
Response:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}