Skip to content

Instantly share code, notes, and snippets.

@Fkawala
Last active October 19, 2016 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fkawala/654093301c47241386b5cd4e02791e56 to your computer and use it in GitHub Desktop.
Save Fkawala/654093301c47241386b5cd4e02791e56 to your computer and use it in GitHub Desktop.
google cloud logging protobuff RequestLog
from google.cloud import logging
from google.protobuf.struct_pb2 import Struct, Value, ListValue
client = logging.Client()
logger = client.logger('test')
line = Struct(fields={'time': Value(string_value='2016-09-04T13:00:08.139759Z'),
'severity': Value(string_value='INFO'),
'logMessage': Value(string_value='Simply testing')})
lines = ListValue()
lines.values.add(struct_value=line)
pb_fields = {'@type': Value(string_value='type.googleapis.com/google.appengine.logging.v1.RequestLog'),
'startTime':Value(string_value='2016-09-04T13:00:08.117102Z'),
'endTime':Value(string_value='2016-09-04T13:00:08.117102Z'),
'latency':Value(string_value='0s'),
'responseSize':Value(string_value='349'),
'userAgent': Value(string_value='agent'),
'resource': Value(string_value='test resource'),
'line': Value(list_value=lines)}
labels = {'serviceName': 'custom.googleapis.com',
'custom.googleapis.com/primary_key': 'fake_module',
'custom.googleapis.com/secondary_key': 'fake_version',
'zone': 'us6'}
logger.log_proto(Struct(fields=pb_fields), labels=labels)
# Dockerfile extending the generic Python image with application files for a
# single application.
FROM ubuntu:latest
# And add a bunch of packages.
RUN apt-get update
RUN apt-get install -y \
python-pip \
python-crypto \
python-openssl
ADD requirements /tmp/requirements
RUN pip install -r /tmp/requirements
ENV GCLOUD_PROJECT project
ENV GOOGLE_APPLICATION_CREDENTIALS credentials.json
ADD . /app
WORKDIR /app
CMD python do_log.py
google-cloud==0.20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment