Skip to content

Commit 0552b17

Browse files
Source PostHog: add support for self-hosted instances (#6058)
1 parent e837048 commit 0552b17

File tree

6 files changed

+41
-18
lines changed

6 files changed

+41
-18
lines changed

airbyte-config/init/src/main/resources/config/STANDARD_SOURCE_DEFINITION/af6d50ee-dddf-4126-a8ee-7faee990774f.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"sourceDefinitionId": "af6d50ee-dddf-4126-a8ee-7faee990774f",
33
"name": "PostHog",
44
"dockerRepository": "airbyte/source-posthog",
5-
"dockerImageTag": "0.1.3",
5+
"dockerImageTag": "0.1.4",
66
"documentationUrl": "https://docs.airbyte.io/integrations/sources/posthog"
77
}

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
- sourceDefinitionId: af6d50ee-dddf-4126-a8ee-7faee990774f
6868
name: PostHog
6969
dockerRepository: airbyte/source-posthog
70-
dockerImageTag: 0.1.3
70+
dockerImageTag: 0.1.4
7171
documentationUrl: https://docs.airbyte.io/integrations/sources/posthog
7272
- sourceDefinitionId: cd42861b-01fc-4658-a8ab-5d11d0510f01
7373
name: Recurly

airbyte-integrations/connectors/source-posthog/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ RUN pip install .
1212
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1313
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1414

15-
LABEL io.airbyte.version=0.1.3
15+
LABEL io.airbyte.version=0.1.4
1616
LABEL io.airbyte.name=airbyte/source-posthog

airbyte-integrations/connectors/source-posthog/source_posthog/source.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@
4646
Trends,
4747
)
4848

49+
DEFAULT_BASE_URL = "https://app.posthog.com"
50+
4951

5052
class SourcePosthog(AbstractSource):
5153
def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, Any]:
5254
try:
5355
_ = pendulum.parse(config["start_date"])
5456
authenticator = TokenAuthenticator(token=config["api_key"])
55-
stream = PingMe(authenticator=authenticator)
57+
base_url = config.get("base_url", DEFAULT_BASE_URL)
58+
59+
stream = PingMe(authenticator=authenticator, base_url=base_url)
5660
records = stream.read_records(sync_mode=SyncMode.full_refresh)
5761
_ = next(records)
5862
return True, None
@@ -69,15 +73,17 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
6973
This stream was requested to be removed due to this reason.
7074
"""
7175
authenticator = TokenAuthenticator(token=config["api_key"])
76+
base_url = config.get("base_url", DEFAULT_BASE_URL)
77+
7278
return [
73-
Annotations(authenticator=authenticator, start_date=config["start_date"]),
74-
Cohorts(authenticator=authenticator),
75-
Events(authenticator=authenticator, start_date=config["start_date"]),
76-
EventsSessions(authenticator=authenticator),
77-
FeatureFlags(authenticator=authenticator),
78-
Insights(authenticator=authenticator),
79-
InsightsPath(authenticator=authenticator),
80-
InsightsSessions(authenticator=authenticator),
81-
Persons(authenticator=authenticator),
82-
Trends(authenticator=authenticator),
79+
Annotations(authenticator=authenticator, start_date=config["start_date"], base_url=base_url),
80+
Cohorts(authenticator=authenticator, base_url=base_url),
81+
Events(authenticator=authenticator, start_date=config["start_date"], base_url=base_url),
82+
EventsSessions(authenticator=authenticator, base_url=base_url),
83+
FeatureFlags(authenticator=authenticator, base_url=base_url),
84+
Insights(authenticator=authenticator, base_url=base_url),
85+
InsightsPath(authenticator=authenticator, base_url=base_url),
86+
InsightsSessions(authenticator=authenticator, base_url=base_url),
87+
Persons(authenticator=authenticator, base_url=base_url),
88+
Trends(authenticator=authenticator, base_url=base_url),
8389
]

airbyte-integrations/connectors/source-posthog/source_posthog/spec.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@
1212
"type": "string",
1313
"description": "The date from which you'd like to replicate the data",
1414
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$",
15-
"examples": "2021-01-01T00:00:00.000000Z"
15+
"examples": [
16+
"2021-01-01T00:00:00.000000Z"
17+
]
1618
},
1719
"api_key": {
1820
"type": "string",
1921
"airbyte_secret": true,
2022
"description": "API Key. See the <a href=\"https://docs.airbyte.io/integrations/sources/posthog\">docs</a> for information on how to generate this key."
23+
},
24+
"base_url": {
25+
"type": "string",
26+
"default": "https://app.posthog.com",
27+
"description": "Base PostHog url. Defaults to PostHog Cloud (https://app.posthog.com).",
28+
"examples": [
29+
"https://posthog.example.com"
30+
]
2131
}
2232
}
2333
}

airbyte-integrations/connectors/source-posthog/source_posthog/streams.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@
3434

3535

3636
class PosthogStream(HttpStream, ABC):
37-
url_base = "https://app.posthog.com/api/"
3837
primary_key = "id"
3938
data_field = "results"
4039

40+
def __init__(self, base_url: str, **kwargs):
41+
super().__init__(**kwargs)
42+
self._url_base = f"{base_url}/api/"
43+
44+
@property
45+
def url_base(self) -> str:
46+
return self._url_base
47+
4148
def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
4249
resp_json = response.json()
4350
if resp_json.get("next"):
@@ -76,8 +83,8 @@ class IncrementalPosthogStream(PosthogStream, ABC):
7683

7784
state_checkpoint_interval = math.inf
7885

79-
def __init__(self, start_date: str, **kwargs):
80-
super().__init__(**kwargs)
86+
def __init__(self, base_url: str, start_date: str, **kwargs):
87+
super().__init__(base_url=base_url, **kwargs)
8188
self._start_date = start_date
8289
self._initial_state = None # we need to keep it here because next_page_token doesn't accept state argument
8390

0 commit comments

Comments
 (0)