# Path: autopush/utils.py
# def get_ec2_instance_id():
#     # type: () -> Optional[str]
#     """Fetch the EC2 instance-id
# 
#     """
#     try:
#         resp = requests.get(
#             "http://169.254.169.254/latest/meta-data/instance-id",
#             timeout=1)
#         return resp.content
#     except (requests.HTTPError, requests.ConnectionError):
#         return None


import io
import json
import Queue
import pkg_resources
import socket
import sys
import time
import threading
import boto3
import raven
from typing import Any  # noqa
from raven.transport.twisted import TwistedHTTPTransport
from raven.utils.stacks import iter_stack_frames
from twisted.internet import reactor
from twisted.logger import (
    formatEvent,
    formatEventAsClassicLogText,
    globalLogBeginner,
    globalLogPublisher,
    LogLevel,
    ILogObserver
)
from zope.interface import implementer
from autopush.utils import get_ec2_instance_id
            msg["Fields"].update(
                to_fields(ti.iteritems())
            )

        # Add the nicely formatted message
        msg["Fields"]["message"] = formatEvent(event)
        return json.dumps(msg, skipkeys=True) + "\n"

    def start(self):
        if self._filename:
            self._output = io.open(self._filename, "a", encoding="utf-8")
        if self.firehose:
            self.firehose.start()
        begin_or_register(self)

    def stop(self):
        globalLogPublisher.removeObserver(self)
        if self._filename:
            self._output.close()
            self._output = None
        if self.firehose:
            self.firehose.stop()

    @classmethod
    def setup_logging(cls, logger_name, log_level="info", log_format="json",
                      log_output="stdout", sentry_dsn=None,
                      firehose_delivery_stream=None,
                      no_aws=False):
        global instance_id_or_hostname
        if not instance_id_or_hostname:

# Path: autopush/utils.py
# def get_ec2_instance_id():
#     # type: () -> Optional[str]
#     """Fetch the EC2 instance-id
# 
#     """
#     try:
#         resp = requests.get(
#             "http://169.254.169.254/latest/meta-data/instance-id",
#             timeout=1)
#         return resp.content
#     except (requests.HTTPError, requests.ConnectionError):
#         return None


# Path: autopush/logging.py
import io
import json
import Queue
import pkg_resources
import socket
import sys
import time
import threading
import boto3
import raven
from typing import Any  # noqa
from raven.transport.twisted import TwistedHTTPTransport
from raven.utils.stacks import iter_stack_frames
from twisted.internet import reactor
from twisted.logger import (
    formatEvent,
    formatEventAsClassicLogText,
    globalLogBeginner,
    globalLogPublisher,
    LogLevel,
    ILogObserver
)
from zope.interface import implementer
from autopush.utils import get_ec2_instance_id

            msg["Fields"].update(
                to_fields(ti.iteritems())
            )

        # Add the nicely formatted message
        msg["Fields"]["message"] = formatEvent(event)
        return json.dumps(msg, skipkeys=True) + "\n"

    def start(self):
        if self._filename:
            self._output = io.open(self._filename, "a", encoding="utf-8")
        if self.firehose:
            self.firehose.start()
        begin_or_register(self)

    def stop(self):
        globalLogPublisher.removeObserver(self)
        if self._filename:
            self._output.close()
            self._output = None
        if self.firehose:
            self.firehose.stop()

    @classmethod
    def setup_logging(cls, logger_name, log_level="info", log_format="json",
                      log_output="stdout", sentry_dsn=None,
                      firehose_delivery_stream=None,
                      no_aws=False):
        global instance_id_or_hostname
        if not instance_id_or_hostname:

            instance_id = None if no_aws else get_ec2_instance_id()