firecrawl-otel 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- firecrawl_otel-0.1.0/.gitignore +10 -0
- firecrawl_otel-0.1.0/LICENSE +202 -0
- firecrawl_otel-0.1.0/PKG-INFO +334 -0
- firecrawl_otel-0.1.0/README.md +98 -0
- firecrawl_otel-0.1.0/examples/.env.example +19 -0
- firecrawl_otel-0.1.0/examples/app.py +57 -0
- firecrawl_otel-0.1.0/examples/otel_setup.py +52 -0
- firecrawl_otel-0.1.0/examples/requirements.txt +8 -0
- firecrawl_otel-0.1.0/pyproject.toml +70 -0
- firecrawl_otel-0.1.0/src/firecrawl_otel/__init__.py +11 -0
- firecrawl_otel-0.1.0/src/firecrawl_otel/instrumentor.py +250 -0
- firecrawl_otel-0.1.0/src/firecrawl_otel/version.py +1 -0
- firecrawl_otel-0.1.0/tests/test_instrumentor.py +188 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: firecrawl-otel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: OpenTelemetry instrumentation for the Firecrawl SDK — ship scrape/crawl/search traces and metrics to SigNoz or any OTLP backend.
|
|
5
|
+
Project-URL: Homepage, https://github.com/gkarthi-signoz/firecrawl-otel
|
|
6
|
+
Project-URL: Source, https://github.com/gkarthi-signoz/firecrawl-otel
|
|
7
|
+
Project-URL: Issues, https://github.com/gkarthi-signoz/firecrawl-otel/issues
|
|
8
|
+
Author-email: Goutham Karthi <goutham@signoz.io>
|
|
9
|
+
License:
|
|
10
|
+
Apache License
|
|
11
|
+
Version 2.0, January 2004
|
|
12
|
+
http://www.apache.org/licenses/
|
|
13
|
+
|
|
14
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
15
|
+
|
|
16
|
+
1. Definitions.
|
|
17
|
+
|
|
18
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
19
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
20
|
+
|
|
21
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
22
|
+
the copyright owner that is granting the License.
|
|
23
|
+
|
|
24
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
25
|
+
other entities that control, are controlled by, or are under common
|
|
26
|
+
control with that entity. For the purposes of this definition,
|
|
27
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
28
|
+
direction or management of such entity, whether by contract or
|
|
29
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
30
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
31
|
+
|
|
32
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
33
|
+
exercising permissions granted by this License.
|
|
34
|
+
|
|
35
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
36
|
+
including but not limited to software source code, documentation
|
|
37
|
+
source, and configuration files.
|
|
38
|
+
|
|
39
|
+
"Object" form shall mean any form resulting from mechanical
|
|
40
|
+
transformation or translation of a Source form, including but
|
|
41
|
+
not limited to compiled object code, generated documentation,
|
|
42
|
+
and conversions to other media types.
|
|
43
|
+
|
|
44
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
45
|
+
Object form, made available under the License, as indicated by a
|
|
46
|
+
copyright notice that is included in or attached to the work
|
|
47
|
+
(an example is provided in the Appendix below).
|
|
48
|
+
|
|
49
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
50
|
+
form, that is based on (or derived from) the Work and for which the
|
|
51
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
52
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
53
|
+
of this License, Derivative Works shall not include works that remain
|
|
54
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
55
|
+
the Work and Derivative Works thereof.
|
|
56
|
+
|
|
57
|
+
"Contribution" shall mean any work of authorship, including
|
|
58
|
+
the original version of the Work and any modifications or additions
|
|
59
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
60
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
61
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
62
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
63
|
+
means any form of electronic, verbal, or written communication sent
|
|
64
|
+
to the Licensor or its representatives, including but not limited to
|
|
65
|
+
communication on electronic mailing lists, source code control systems,
|
|
66
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
67
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
68
|
+
excluding communication that is conspicuously marked or otherwise
|
|
69
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
70
|
+
|
|
71
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
72
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
73
|
+
subsequently incorporated within the Work.
|
|
74
|
+
|
|
75
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
79
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
80
|
+
Work and such Derivative Works in Source or Object form.
|
|
81
|
+
|
|
82
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
83
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
84
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
85
|
+
(except as stated in this section) patent license to make, have made,
|
|
86
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
87
|
+
where such license applies only to those patent claims licensable
|
|
88
|
+
by such Contributor that are necessarily infringed by their
|
|
89
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
90
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
91
|
+
institute patent litigation against any entity (including a
|
|
92
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
93
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
94
|
+
or contributory patent infringement, then any patent licenses
|
|
95
|
+
granted to You under this License for that Work shall terminate
|
|
96
|
+
as of the date such litigation is filed.
|
|
97
|
+
|
|
98
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
99
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
100
|
+
modifications, and in Source or Object form, provided that You
|
|
101
|
+
meet the following conditions:
|
|
102
|
+
|
|
103
|
+
(a) You must give any other recipients of the Work or
|
|
104
|
+
Derivative Works a copy of this License; and
|
|
105
|
+
|
|
106
|
+
(b) You must cause any modified files to carry prominent notices
|
|
107
|
+
stating that You changed the files; and
|
|
108
|
+
|
|
109
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
110
|
+
that You distribute, all copyright, patent, trademark, and
|
|
111
|
+
attribution notices from the Source form of the Work,
|
|
112
|
+
excluding those notices that do not pertain to any part of
|
|
113
|
+
the Derivative Works; and
|
|
114
|
+
|
|
115
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
116
|
+
distribution, then any Derivative Works that You distribute must
|
|
117
|
+
include a readable copy of the attribution notices contained
|
|
118
|
+
within such NOTICE file, excluding those notices that do not
|
|
119
|
+
pertain to any part of the Derivative Works, in at least one
|
|
120
|
+
of the following places: within a NOTICE text file distributed
|
|
121
|
+
as part of the Derivative Works; within the Source form or
|
|
122
|
+
documentation, if provided along with the Derivative Works; or,
|
|
123
|
+
within a display generated by the Derivative Works, if and
|
|
124
|
+
wherever such third-party notices normally appear. The contents
|
|
125
|
+
of the NOTICE file are for informational purposes only and
|
|
126
|
+
do not modify the License. You may add Your own attribution
|
|
127
|
+
notices within Derivative Works that You distribute, alongside
|
|
128
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
129
|
+
that such additional attribution notices cannot be construed
|
|
130
|
+
as modifying the License.
|
|
131
|
+
|
|
132
|
+
You may add Your own copyright statement to Your modifications and
|
|
133
|
+
may provide additional or different license terms and conditions
|
|
134
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
135
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
136
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
137
|
+
the conditions stated in this License.
|
|
138
|
+
|
|
139
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
140
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
141
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
142
|
+
this License, without any additional terms or conditions.
|
|
143
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
144
|
+
the terms of any separate license agreement you may have executed
|
|
145
|
+
with Licensor regarding such Contributions.
|
|
146
|
+
|
|
147
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
148
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
149
|
+
except as required for reasonable and customary use in describing the
|
|
150
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
151
|
+
|
|
152
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
153
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
154
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
155
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
156
|
+
implied, including, without limitation, any warranties or conditions
|
|
157
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
158
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
159
|
+
appropriateness of using or redistributing the Work and assume any
|
|
160
|
+
risks associated with Your exercise of permissions under this License.
|
|
161
|
+
|
|
162
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
163
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
164
|
+
unless required by applicable law (such as deliberate and grossly
|
|
165
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
166
|
+
liable to You for damages, including any direct, indirect, special,
|
|
167
|
+
incidental, or consequential damages of any character arising as a
|
|
168
|
+
result of this License or out of the use or inability to use the
|
|
169
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
170
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
171
|
+
other commercial damages or losses), even if such Contributor
|
|
172
|
+
has been advised of the possibility of such damages.
|
|
173
|
+
|
|
174
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
175
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
176
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
177
|
+
or other liability obligations and/or rights consistent with this
|
|
178
|
+
License. However, in accepting such obligations, You may act only
|
|
179
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
180
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
181
|
+
defend, and hold each Contributor harmless for any liability
|
|
182
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
183
|
+
of your accepting any such warranty or additional liability.
|
|
184
|
+
|
|
185
|
+
END OF TERMS AND CONDITIONS
|
|
186
|
+
|
|
187
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
188
|
+
|
|
189
|
+
To apply the Apache License to your work, attach the following
|
|
190
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
191
|
+
replaced with your own identifying information. (Don't include
|
|
192
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
193
|
+
comment syntax for the file format. We also recommend that a
|
|
194
|
+
file or class name and description of purpose be included on the
|
|
195
|
+
same "printed page" as the copyright notice for easier
|
|
196
|
+
identification within third-party archives.
|
|
197
|
+
|
|
198
|
+
Copyright [yyyy] [name of copyright owner]
|
|
199
|
+
|
|
200
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
201
|
+
you may not use this file except in compliance with the License.
|
|
202
|
+
You may obtain a copy of the License at
|
|
203
|
+
|
|
204
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
205
|
+
|
|
206
|
+
Unless required by applicable law or agreed to in writing, software
|
|
207
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
208
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
209
|
+
See the License for the specific language governing permissions and
|
|
210
|
+
limitations under the License.
|
|
211
|
+
License-File: LICENSE
|
|
212
|
+
Keywords: firecrawl,instrumentation,metrics,observability,opentelemetry,otel,signoz,tracing,web-scraping
|
|
213
|
+
Classifier: Development Status :: 4 - Beta
|
|
214
|
+
Classifier: Intended Audience :: Developers
|
|
215
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
216
|
+
Classifier: Operating System :: OS Independent
|
|
217
|
+
Classifier: Programming Language :: Python :: 3
|
|
218
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
219
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
220
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
221
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
222
|
+
Classifier: Topic :: System :: Monitoring
|
|
223
|
+
Requires-Python: >=3.9
|
|
224
|
+
Requires-Dist: opentelemetry-api>=1.20.0
|
|
225
|
+
Requires-Dist: opentelemetry-instrumentation>=0.41b0
|
|
226
|
+
Requires-Dist: wrapt>=1.14.0
|
|
227
|
+
Provides-Extra: dev
|
|
228
|
+
Requires-Dist: build; extra == 'dev'
|
|
229
|
+
Requires-Dist: firecrawl-py>=2.0.0; extra == 'dev'
|
|
230
|
+
Requires-Dist: opentelemetry-sdk>=1.20.0; extra == 'dev'
|
|
231
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
232
|
+
Requires-Dist: twine; extra == 'dev'
|
|
233
|
+
Provides-Extra: instruments
|
|
234
|
+
Requires-Dist: firecrawl-py>=2.0.0; extra == 'instruments'
|
|
235
|
+
Description-Content-Type: text/markdown
|
|
236
|
+
|
|
237
|
+
# firecrawl-otel
|
|
238
|
+
|
|
239
|
+
OpenTelemetry instrumentation for the [Firecrawl](https://firecrawl.dev) Python
|
|
240
|
+
SDK. Trace every `scrape` / `crawl` / `search` / `map` / `extract` call and ship
|
|
241
|
+
the traces and metrics to [SigNoz](https://signoz.io) — or any OTLP backend —
|
|
242
|
+
**without changing your Firecrawl call sites**.
|
|
243
|
+
|
|
244
|
+
Firecrawl does not emit OpenTelemetry itself, so this package instruments it on
|
|
245
|
+
the client side using the standard OpenTelemetry `BaseInstrumentor` pattern.
|
|
246
|
+
|
|
247
|
+
## Install
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
pip install firecrawl-otel
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Quickstart
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
from firecrawl import Firecrawl
|
|
257
|
+
from firecrawl_otel import FirecrawlInstrumentor
|
|
258
|
+
|
|
259
|
+
FirecrawlInstrumentor().instrument() # once, at startup
|
|
260
|
+
|
|
261
|
+
app = Firecrawl(api_key="fc-...") # your normal client — unchanged
|
|
262
|
+
doc = app.scrape("https://example.com") # automatically traced
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Point the telemetry at SigNoz with standard OpenTelemetry environment variables:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
# SigNoz Cloud (region = us | us2 | eu | eu2 | in | in2)
|
|
269
|
+
export OTEL_SERVICE_NAME=my-app
|
|
270
|
+
export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.us.signoz.cloud:443
|
|
271
|
+
export OTEL_EXPORTER_OTLP_HEADERS=signoz-ingestion-key=<your-key>
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
For self-hosted SigNoz use `http://localhost:4317` and no headers.
|
|
275
|
+
|
|
276
|
+
### Zero-code option
|
|
277
|
+
|
|
278
|
+
Because the package registers an `opentelemetry_instrumentor` entry point, the
|
|
279
|
+
OpenTelemetry CLI can enable it with no code change at all:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
pip install firecrawl-otel opentelemetry-distro opentelemetry-exporter-otlp
|
|
283
|
+
opentelemetry-bootstrap -a install
|
|
284
|
+
opentelemetry-instrument python your_app.py
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## What you get in SigNoz
|
|
288
|
+
|
|
289
|
+
**Traces** — one span per Firecrawl call:
|
|
290
|
+
|
|
291
|
+
| Span attribute | Example |
|
|
292
|
+
| --- | --- |
|
|
293
|
+
| `firecrawl.operation` | `scrape`, `crawl`, `search`, `map` |
|
|
294
|
+
| `url.full` | `https://example.com` |
|
|
295
|
+
| `firecrawl.query` | `what is opentelemetry` (search) |
|
|
296
|
+
| `firecrawl.formats` | `markdown,html` |
|
|
297
|
+
| `firecrawl.results` | `5` |
|
|
298
|
+
| `firecrawl.credits_used` | `12` |
|
|
299
|
+
| `firecrawl.status` | `completed` |
|
|
300
|
+
|
|
301
|
+
**Metrics:**
|
|
302
|
+
|
|
303
|
+
| Metric | Type | Description |
|
|
304
|
+
| --- | --- | --- |
|
|
305
|
+
| `firecrawl.requests` | counter | Calls, tagged by `firecrawl.operation` + `outcome` (ok/error) |
|
|
306
|
+
| `firecrawl.request.duration` | histogram (ms) | Latency per call |
|
|
307
|
+
| `firecrawl.credits.used` | counter | Firecrawl credits consumed |
|
|
308
|
+
| `firecrawl.results.returned` | histogram | Documents/pages/results returned |
|
|
309
|
+
|
|
310
|
+
## Notes
|
|
311
|
+
|
|
312
|
+
- **Call `instrument()` before creating the `Firecrawl` client.** The unified
|
|
313
|
+
client binds its methods at construction time, so instrument at startup (as in
|
|
314
|
+
the quickstart) — clients created afterwards are traced.
|
|
315
|
+
- **This library configures no exporters.** Exporter setup stays with your app
|
|
316
|
+
(the `OTEL_*` env vars above, or `opentelemetry-instrument`). That keeps it
|
|
317
|
+
composable with the rest of your OpenTelemetry setup.
|
|
318
|
+
- Pass explicit providers if you don't use the globals:
|
|
319
|
+
`FirecrawlInstrumentor().instrument(tracer_provider=tp, meter_provider=mp)`.
|
|
320
|
+
- Disable again with `FirecrawlInstrumentor().uninstrument()`.
|
|
321
|
+
- A runnable end-to-end demo (scrape → search → crawl) lives in
|
|
322
|
+
[`examples/`](./examples).
|
|
323
|
+
|
|
324
|
+
## Development
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
pip install -e ".[dev]"
|
|
328
|
+
pytest
|
|
329
|
+
python -m build && twine check dist/*
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## License
|
|
333
|
+
|
|
334
|
+
Apache-2.0
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# firecrawl-otel
|
|
2
|
+
|
|
3
|
+
OpenTelemetry instrumentation for the [Firecrawl](https://firecrawl.dev) Python
|
|
4
|
+
SDK. Trace every `scrape` / `crawl` / `search` / `map` / `extract` call and ship
|
|
5
|
+
the traces and metrics to [SigNoz](https://signoz.io) — or any OTLP backend —
|
|
6
|
+
**without changing your Firecrawl call sites**.
|
|
7
|
+
|
|
8
|
+
Firecrawl does not emit OpenTelemetry itself, so this package instruments it on
|
|
9
|
+
the client side using the standard OpenTelemetry `BaseInstrumentor` pattern.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install firecrawl-otel
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quickstart
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from firecrawl import Firecrawl
|
|
21
|
+
from firecrawl_otel import FirecrawlInstrumentor
|
|
22
|
+
|
|
23
|
+
FirecrawlInstrumentor().instrument() # once, at startup
|
|
24
|
+
|
|
25
|
+
app = Firecrawl(api_key="fc-...") # your normal client — unchanged
|
|
26
|
+
doc = app.scrape("https://example.com") # automatically traced
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Point the telemetry at SigNoz with standard OpenTelemetry environment variables:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# SigNoz Cloud (region = us | us2 | eu | eu2 | in | in2)
|
|
33
|
+
export OTEL_SERVICE_NAME=my-app
|
|
34
|
+
export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.us.signoz.cloud:443
|
|
35
|
+
export OTEL_EXPORTER_OTLP_HEADERS=signoz-ingestion-key=<your-key>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For self-hosted SigNoz use `http://localhost:4317` and no headers.
|
|
39
|
+
|
|
40
|
+
### Zero-code option
|
|
41
|
+
|
|
42
|
+
Because the package registers an `opentelemetry_instrumentor` entry point, the
|
|
43
|
+
OpenTelemetry CLI can enable it with no code change at all:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install firecrawl-otel opentelemetry-distro opentelemetry-exporter-otlp
|
|
47
|
+
opentelemetry-bootstrap -a install
|
|
48
|
+
opentelemetry-instrument python your_app.py
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## What you get in SigNoz
|
|
52
|
+
|
|
53
|
+
**Traces** — one span per Firecrawl call:
|
|
54
|
+
|
|
55
|
+
| Span attribute | Example |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `firecrawl.operation` | `scrape`, `crawl`, `search`, `map` |
|
|
58
|
+
| `url.full` | `https://example.com` |
|
|
59
|
+
| `firecrawl.query` | `what is opentelemetry` (search) |
|
|
60
|
+
| `firecrawl.formats` | `markdown,html` |
|
|
61
|
+
| `firecrawl.results` | `5` |
|
|
62
|
+
| `firecrawl.credits_used` | `12` |
|
|
63
|
+
| `firecrawl.status` | `completed` |
|
|
64
|
+
|
|
65
|
+
**Metrics:**
|
|
66
|
+
|
|
67
|
+
| Metric | Type | Description |
|
|
68
|
+
| --- | --- | --- |
|
|
69
|
+
| `firecrawl.requests` | counter | Calls, tagged by `firecrawl.operation` + `outcome` (ok/error) |
|
|
70
|
+
| `firecrawl.request.duration` | histogram (ms) | Latency per call |
|
|
71
|
+
| `firecrawl.credits.used` | counter | Firecrawl credits consumed |
|
|
72
|
+
| `firecrawl.results.returned` | histogram | Documents/pages/results returned |
|
|
73
|
+
|
|
74
|
+
## Notes
|
|
75
|
+
|
|
76
|
+
- **Call `instrument()` before creating the `Firecrawl` client.** The unified
|
|
77
|
+
client binds its methods at construction time, so instrument at startup (as in
|
|
78
|
+
the quickstart) — clients created afterwards are traced.
|
|
79
|
+
- **This library configures no exporters.** Exporter setup stays with your app
|
|
80
|
+
(the `OTEL_*` env vars above, or `opentelemetry-instrument`). That keeps it
|
|
81
|
+
composable with the rest of your OpenTelemetry setup.
|
|
82
|
+
- Pass explicit providers if you don't use the globals:
|
|
83
|
+
`FirecrawlInstrumentor().instrument(tracer_provider=tp, meter_provider=mp)`.
|
|
84
|
+
- Disable again with `FirecrawlInstrumentor().uninstrument()`.
|
|
85
|
+
- A runnable end-to-end demo (scrape → search → crawl) lives in
|
|
86
|
+
[`examples/`](./examples).
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install -e ".[dev]"
|
|
92
|
+
pytest
|
|
93
|
+
python -m build && twine check dist/*
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
Apache-2.0
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# ---- Firecrawl ----
|
|
2
|
+
# Get your key at https://www.firecrawl.dev/app/api-keys
|
|
3
|
+
FIRECRAWL_API_KEY=fc-YOUR_API_KEY
|
|
4
|
+
|
|
5
|
+
# ---- SigNoz / OpenTelemetry ----
|
|
6
|
+
OTEL_SERVICE_NAME=firecrawl-demo
|
|
7
|
+
|
|
8
|
+
# --- SigNoz Cloud ---
|
|
9
|
+
# Endpoint: https://ingest.<region>.signoz.cloud:443 (region = us | us2 | eu | eu2 | in | in2)
|
|
10
|
+
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.us.signoz.cloud:443
|
|
11
|
+
# Ingestion key: SigNoz -> Settings -> Ingestion Settings
|
|
12
|
+
OTEL_EXPORTER_OTLP_HEADERS=signoz-ingestion-key=YOUR_INGESTION_KEY
|
|
13
|
+
|
|
14
|
+
# --- Self-hosted SigNoz (use these two instead of the pair above) ---
|
|
15
|
+
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
|
|
16
|
+
# OTEL_EXPORTER_OTLP_HEADERS=
|
|
17
|
+
|
|
18
|
+
# Optional resource attributes
|
|
19
|
+
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=demo,service.version=0.1.0
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Firecrawl -> SigNoz starter demo, using the firecrawl-otel instrumentor.
|
|
2
|
+
|
|
3
|
+
Runs a small web-data workflow (scrape + search + crawl). Because the SDK is
|
|
4
|
+
instrumented, every call is traced and measured automatically and exported to
|
|
5
|
+
SigNoz over OTLP. Open SigNoz afterwards and look for the service named by
|
|
6
|
+
OTEL_SERVICE_NAME (default: firecrawl-demo).
|
|
7
|
+
|
|
8
|
+
Run:
|
|
9
|
+
cp .env.example .env # fill in FIRECRAWL_API_KEY and SigNoz values
|
|
10
|
+
pip install -r requirements.txt
|
|
11
|
+
python app.py
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
from dotenv import load_dotenv
|
|
17
|
+
from firecrawl import Firecrawl
|
|
18
|
+
from opentelemetry import trace
|
|
19
|
+
|
|
20
|
+
from firecrawl_otel import FirecrawlInstrumentor
|
|
21
|
+
from otel_setup import init_otel, shutdown_otel
|
|
22
|
+
|
|
23
|
+
load_dotenv()
|
|
24
|
+
init_otel() # exporters first (app-side setup)
|
|
25
|
+
FirecrawlInstrumentor().instrument() # then patch the Firecrawl SDK
|
|
26
|
+
|
|
27
|
+
tracer = trace.get_tracer("firecrawl.demo")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def main() -> None:
|
|
31
|
+
# Plain Firecrawl client — no wrapper. Instrumentation is transparent.
|
|
32
|
+
app = Firecrawl(api_key=os.environ["FIRECRAWL_API_KEY"])
|
|
33
|
+
|
|
34
|
+
# A parent span groups the whole workflow into one trace in SigNoz.
|
|
35
|
+
with tracer.start_as_current_span("firecrawl.demo.workflow"):
|
|
36
|
+
print("Scraping a single page...")
|
|
37
|
+
doc = app.scrape(
|
|
38
|
+
"https://docs.firecrawl.dev/introduction", formats=["markdown"]
|
|
39
|
+
)
|
|
40
|
+
print(f" scraped {len(getattr(doc, 'markdown', None) or '')} chars\n")
|
|
41
|
+
|
|
42
|
+
print("Searching the web...")
|
|
43
|
+
results = app.search("what is OpenTelemetry", limit=3)
|
|
44
|
+
print(f" got {len(getattr(results, 'web', None) or [])} results\n")
|
|
45
|
+
|
|
46
|
+
print("Crawling a small site (depth-limited)...")
|
|
47
|
+
crawl = app.crawl("https://docs.firecrawl.dev", limit=5)
|
|
48
|
+
print(f" crawled {len(getattr(crawl, 'data', None) or [])} pages\n")
|
|
49
|
+
|
|
50
|
+
print("Done. Flushing telemetry to SigNoz...")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
try:
|
|
55
|
+
main()
|
|
56
|
+
finally:
|
|
57
|
+
shutdown_otel() # ensure buffered spans/metrics are delivered
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""OpenTelemetry exporter bootstrap for the demo (the *application* side).
|
|
2
|
+
|
|
3
|
+
Note this lives in `examples/`, not in the `firecrawl_otel` package: a good
|
|
4
|
+
instrumentation library instruments but does not configure exporters. Your app
|
|
5
|
+
(or the `opentelemetry-instrument` CLI) owns exporter setup. Endpoint, headers
|
|
6
|
+
and service name are read from the standard OTEL_* environment variables, so the
|
|
7
|
+
same code targets SigNoz Cloud or a self-hosted SigNoz with no change.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
from opentelemetry import metrics, trace
|
|
13
|
+
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
|
|
14
|
+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
|
15
|
+
from opentelemetry.sdk.metrics import MeterProvider
|
|
16
|
+
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
|
|
17
|
+
from opentelemetry.sdk.resources import Resource
|
|
18
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
19
|
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
|
20
|
+
|
|
21
|
+
_INITIALIZED = False
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def init_otel() -> None:
|
|
25
|
+
"""Wire up trace + metric exporters to SigNoz. Idempotent."""
|
|
26
|
+
global _INITIALIZED
|
|
27
|
+
if _INITIALIZED:
|
|
28
|
+
return
|
|
29
|
+
|
|
30
|
+
resource = Resource.create() # reads OTEL_SERVICE_NAME / OTEL_RESOURCE_ATTRIBUTES
|
|
31
|
+
|
|
32
|
+
tracer_provider = TracerProvider(resource=resource)
|
|
33
|
+
tracer_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
|
|
34
|
+
trace.set_tracer_provider(tracer_provider)
|
|
35
|
+
|
|
36
|
+
reader = PeriodicExportingMetricReader(
|
|
37
|
+
OTLPMetricExporter(), export_interval_millis=15000
|
|
38
|
+
)
|
|
39
|
+
metrics.set_meter_provider(MeterProvider(resource=resource, metric_readers=[reader]))
|
|
40
|
+
|
|
41
|
+
_INITIALIZED = True
|
|
42
|
+
print(
|
|
43
|
+
f"[otel] exporting service "
|
|
44
|
+
f"'{os.getenv('OTEL_SERVICE_NAME', 'unknown_service')}' to "
|
|
45
|
+
f"{os.getenv('OTEL_EXPORTER_OTLP_ENDPOINT', '<unset>')}"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def shutdown_otel() -> None:
|
|
50
|
+
"""Flush buffered spans/metrics before the process exits."""
|
|
51
|
+
trace.get_tracer_provider().shutdown()
|
|
52
|
+
metrics.get_meter_provider().shutdown()
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# The instrumentation package (installs firecrawl-py via the extra)
|
|
2
|
+
firecrawl-otel[instruments]
|
|
3
|
+
|
|
4
|
+
# App-side OpenTelemetry SDK + OTLP exporter (owned by the app, not the library)
|
|
5
|
+
opentelemetry-sdk>=1.20.0
|
|
6
|
+
opentelemetry-exporter-otlp>=1.20.0
|
|
7
|
+
|
|
8
|
+
python-dotenv>=1.0.0
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "firecrawl-otel"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "OpenTelemetry instrumentation for the Firecrawl SDK — ship scrape/crawl/search traces and metrics to SigNoz or any OTLP backend."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
authors = [{ name = "Goutham Karthi", email = "goutham@signoz.io" }]
|
|
13
|
+
keywords = [
|
|
14
|
+
"firecrawl",
|
|
15
|
+
"opentelemetry",
|
|
16
|
+
"otel",
|
|
17
|
+
"observability",
|
|
18
|
+
"signoz",
|
|
19
|
+
"tracing",
|
|
20
|
+
"metrics",
|
|
21
|
+
"web-scraping",
|
|
22
|
+
"instrumentation",
|
|
23
|
+
]
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 4 - Beta",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"License :: OSI Approved :: Apache Software License",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
"Programming Language :: Python :: 3",
|
|
30
|
+
"Programming Language :: Python :: 3.9",
|
|
31
|
+
"Programming Language :: Python :: 3.10",
|
|
32
|
+
"Programming Language :: Python :: 3.11",
|
|
33
|
+
"Programming Language :: Python :: 3.12",
|
|
34
|
+
"Topic :: System :: Monitoring",
|
|
35
|
+
]
|
|
36
|
+
dependencies = [
|
|
37
|
+
"opentelemetry-api >= 1.20.0",
|
|
38
|
+
"opentelemetry-instrumentation >= 0.41b0",
|
|
39
|
+
"wrapt >= 1.14.0",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.optional-dependencies]
|
|
43
|
+
# `instruments` mirrors the OpenTelemetry-contrib convention: the library this
|
|
44
|
+
# package instruments, pulled only when you actually want to run it.
|
|
45
|
+
instruments = ["firecrawl-py >= 2.0.0"]
|
|
46
|
+
dev = [
|
|
47
|
+
"firecrawl-py >= 2.0.0",
|
|
48
|
+
"opentelemetry-sdk >= 1.20.0",
|
|
49
|
+
"pytest >= 7.0",
|
|
50
|
+
"build",
|
|
51
|
+
"twine",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
# Makes `opentelemetry-instrument python app.py` auto-discover and enable this.
|
|
55
|
+
[project.entry-points.opentelemetry_instrumentor]
|
|
56
|
+
firecrawl = "firecrawl_otel.instrumentor:FirecrawlInstrumentor"
|
|
57
|
+
|
|
58
|
+
[project.urls]
|
|
59
|
+
Homepage = "https://github.com/gkarthi-signoz/firecrawl-otel"
|
|
60
|
+
Source = "https://github.com/gkarthi-signoz/firecrawl-otel"
|
|
61
|
+
Issues = "https://github.com/gkarthi-signoz/firecrawl-otel/issues"
|
|
62
|
+
|
|
63
|
+
[tool.hatch.version]
|
|
64
|
+
path = "src/firecrawl_otel/version.py"
|
|
65
|
+
|
|
66
|
+
[tool.hatch.build.targets.wheel]
|
|
67
|
+
packages = ["src/firecrawl_otel"]
|
|
68
|
+
|
|
69
|
+
[tool.hatch.build.targets.sdist]
|
|
70
|
+
include = ["/src", "/tests", "/examples", "/README.md", "/LICENSE"]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""OpenTelemetry instrumentation for the Firecrawl SDK.
|
|
2
|
+
|
|
3
|
+
Import ``FirecrawlInstrumentor`` and call ``.instrument()`` once at startup to
|
|
4
|
+
trace every Firecrawl scrape/crawl/search/map/extract call and export it to
|
|
5
|
+
SigNoz (or any OTLP backend).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from firecrawl_otel.version import __version__
|
|
9
|
+
from firecrawl_otel.instrumentor import FirecrawlInstrumentor
|
|
10
|
+
|
|
11
|
+
__all__ = ["FirecrawlInstrumentor", "__version__"]
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"""OpenTelemetry instrumentation for the Firecrawl Python SDK.
|
|
2
|
+
|
|
3
|
+
Patches the Firecrawl v2 client so every scrape / crawl / search / map / extract
|
|
4
|
+
/ batch_scrape call emits an OpenTelemetry span and metrics, with no change to
|
|
5
|
+
your Firecrawl call sites:
|
|
6
|
+
|
|
7
|
+
from firecrawl import Firecrawl
|
|
8
|
+
from firecrawl_otel import FirecrawlInstrumentor
|
|
9
|
+
|
|
10
|
+
FirecrawlInstrumentor().instrument() # call before creating the client
|
|
11
|
+
app = Firecrawl(api_key="fc-...")
|
|
12
|
+
app.scrape("https://example.com") # now traced
|
|
13
|
+
|
|
14
|
+
The unified ``firecrawl.Firecrawl`` client binds its methods from
|
|
15
|
+
``firecrawl.v2.client.FirecrawlClient`` at construction time, so instrumentation
|
|
16
|
+
must be enabled *before* the client is created (the normal "instrument at
|
|
17
|
+
startup" pattern).
|
|
18
|
+
|
|
19
|
+
This library only *instruments*; it does not configure exporters. Point your
|
|
20
|
+
telemetry at SigNoz (or any OTLP backend) with the standard ``OTEL_*``
|
|
21
|
+
environment variables, or run under the ``opentelemetry-instrument`` CLI.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import importlib
|
|
25
|
+
import time
|
|
26
|
+
from typing import Any, Collection, Dict, Optional
|
|
27
|
+
|
|
28
|
+
from opentelemetry import metrics, trace
|
|
29
|
+
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
|
30
|
+
from opentelemetry.instrumentation.utils import unwrap
|
|
31
|
+
from opentelemetry.trace import SpanKind, Status, StatusCode
|
|
32
|
+
from wrapt import wrap_function_wrapper
|
|
33
|
+
|
|
34
|
+
from firecrawl_otel.version import __version__
|
|
35
|
+
|
|
36
|
+
# The v2 client class is where these methods are actually defined; the unified
|
|
37
|
+
# `firecrawl.Firecrawl` client delegates to an instance of it.
|
|
38
|
+
_MODULE = "firecrawl.v2.client"
|
|
39
|
+
_CLASS = "FirecrawlClient"
|
|
40
|
+
|
|
41
|
+
# Methods we wrap. Methods absent from the installed SDK version are skipped.
|
|
42
|
+
_INSTRUMENTED_METHODS = (
|
|
43
|
+
"scrape",
|
|
44
|
+
"crawl",
|
|
45
|
+
"search",
|
|
46
|
+
"map",
|
|
47
|
+
"extract",
|
|
48
|
+
"batch_scrape",
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class FirecrawlInstrumentor(BaseInstrumentor):
|
|
53
|
+
"""Instruments the Firecrawl SDK with OpenTelemetry traces and metrics."""
|
|
54
|
+
|
|
55
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
|
56
|
+
return ("firecrawl-py >= 2.0.0",)
|
|
57
|
+
|
|
58
|
+
def _instrument(self, **kwargs: Any) -> None:
|
|
59
|
+
tracer = trace.get_tracer(
|
|
60
|
+
__name__, __version__, kwargs.get("tracer_provider")
|
|
61
|
+
)
|
|
62
|
+
meter = metrics.get_meter(
|
|
63
|
+
__name__, __version__, kwargs.get("meter_provider")
|
|
64
|
+
)
|
|
65
|
+
instruments = _build_instruments(meter)
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
importlib.import_module(_MODULE)
|
|
69
|
+
except ImportError:
|
|
70
|
+
# Unsupported/old SDK layout; instrument nothing rather than crash.
|
|
71
|
+
return
|
|
72
|
+
|
|
73
|
+
for method in _INSTRUMENTED_METHODS:
|
|
74
|
+
try:
|
|
75
|
+
wrap_function_wrapper(
|
|
76
|
+
_MODULE,
|
|
77
|
+
f"{_CLASS}.{method}",
|
|
78
|
+
_make_wrapper(method, tracer, instruments),
|
|
79
|
+
)
|
|
80
|
+
except (AttributeError, ImportError):
|
|
81
|
+
continue
|
|
82
|
+
|
|
83
|
+
def _uninstrument(self, **kwargs: Any) -> None:
|
|
84
|
+
try:
|
|
85
|
+
module = importlib.import_module(_MODULE)
|
|
86
|
+
except ImportError:
|
|
87
|
+
return
|
|
88
|
+
client_cls = getattr(module, _CLASS, None)
|
|
89
|
+
if client_cls is None:
|
|
90
|
+
return
|
|
91
|
+
for method in _INSTRUMENTED_METHODS:
|
|
92
|
+
if hasattr(client_cls, method):
|
|
93
|
+
unwrap(client_cls, method)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# --------------------------------------------------------------------------- #
|
|
97
|
+
# Span / metric wrapping
|
|
98
|
+
# --------------------------------------------------------------------------- #
|
|
99
|
+
def _build_instruments(meter) -> Dict[str, Any]:
|
|
100
|
+
return {
|
|
101
|
+
"requests": meter.create_counter(
|
|
102
|
+
"firecrawl.requests",
|
|
103
|
+
unit="1",
|
|
104
|
+
description="Firecrawl API calls, tagged by operation and outcome",
|
|
105
|
+
),
|
|
106
|
+
"duration": meter.create_histogram(
|
|
107
|
+
"firecrawl.request.duration",
|
|
108
|
+
unit="ms",
|
|
109
|
+
description="Wall-clock duration of a Firecrawl API call",
|
|
110
|
+
),
|
|
111
|
+
"credits": meter.create_counter(
|
|
112
|
+
"firecrawl.credits.used",
|
|
113
|
+
unit="1",
|
|
114
|
+
description="Firecrawl credits consumed (when reported by the API)",
|
|
115
|
+
),
|
|
116
|
+
"results": meter.create_histogram(
|
|
117
|
+
"firecrawl.results.returned",
|
|
118
|
+
unit="1",
|
|
119
|
+
description="Documents/pages/results returned by an operation",
|
|
120
|
+
),
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _make_wrapper(operation: str, tracer, instruments: Dict[str, Any]):
|
|
125
|
+
"""Build a wrapt wrapper for one Firecrawl method."""
|
|
126
|
+
|
|
127
|
+
def wrapper(wrapped, instance, args, kwargs):
|
|
128
|
+
base = {"firecrawl.operation": operation}
|
|
129
|
+
span_attrs = dict(base)
|
|
130
|
+
span_attrs.update(_target_attributes(operation, args, kwargs))
|
|
131
|
+
formats = kwargs.get("formats")
|
|
132
|
+
if formats:
|
|
133
|
+
span_attrs["firecrawl.formats"] = ",".join(map(str, formats))
|
|
134
|
+
|
|
135
|
+
start = time.monotonic()
|
|
136
|
+
with tracer.start_as_current_span(
|
|
137
|
+
f"firecrawl.{operation}", kind=SpanKind.CLIENT, attributes=span_attrs
|
|
138
|
+
) as span:
|
|
139
|
+
try:
|
|
140
|
+
result = wrapped(*args, **kwargs)
|
|
141
|
+
except Exception as exc:
|
|
142
|
+
elapsed_ms = (time.monotonic() - start) * 1000
|
|
143
|
+
span.set_status(Status(StatusCode.ERROR, str(exc)))
|
|
144
|
+
span.record_exception(exc)
|
|
145
|
+
_record_request(instruments, base, "error", elapsed_ms)
|
|
146
|
+
raise
|
|
147
|
+
|
|
148
|
+
elapsed_ms = (time.monotonic() - start) * 1000
|
|
149
|
+
_annotate(span, base, result, instruments)
|
|
150
|
+
_record_request(instruments, base, "ok", elapsed_ms)
|
|
151
|
+
return result
|
|
152
|
+
|
|
153
|
+
return wrapper
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _record_request(
|
|
157
|
+
instruments: Dict[str, Any], base: Dict[str, str], outcome: str, elapsed_ms: float
|
|
158
|
+
) -> None:
|
|
159
|
+
attrs = {**base, "outcome": outcome}
|
|
160
|
+
instruments["requests"].add(1, attrs)
|
|
161
|
+
instruments["duration"].record(elapsed_ms, attrs)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _annotate(
|
|
165
|
+
span, base: Dict[str, str], result: Any, instruments: Dict[str, Any]
|
|
166
|
+
) -> None:
|
|
167
|
+
payload = _as_dict(result)
|
|
168
|
+
|
|
169
|
+
count = _result_count(payload)
|
|
170
|
+
if count is not None:
|
|
171
|
+
span.set_attribute("firecrawl.results", count)
|
|
172
|
+
instruments["results"].record(count, base)
|
|
173
|
+
|
|
174
|
+
credits = _extract_credits(payload)
|
|
175
|
+
if credits is not None:
|
|
176
|
+
span.set_attribute("firecrawl.credits_used", credits)
|
|
177
|
+
instruments["credits"].add(credits, base)
|
|
178
|
+
|
|
179
|
+
status = payload.get("status")
|
|
180
|
+
if status:
|
|
181
|
+
span.set_attribute("firecrawl.status", str(status))
|
|
182
|
+
|
|
183
|
+
# Crawl jobs also report progress counters.
|
|
184
|
+
for key, attr in (("total", "firecrawl.total"), ("completed", "firecrawl.completed")):
|
|
185
|
+
value = payload.get(key)
|
|
186
|
+
if isinstance(value, int):
|
|
187
|
+
span.set_attribute(attr, value)
|
|
188
|
+
|
|
189
|
+
span.set_status(Status(StatusCode.OK))
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# --------------------------------------------------------------------------- #
|
|
193
|
+
# Attribute extraction helpers
|
|
194
|
+
# --------------------------------------------------------------------------- #
|
|
195
|
+
def _target_attributes(operation: str, args, kwargs) -> Dict[str, Any]:
|
|
196
|
+
"""The URL (scrape/crawl/map) or query (search) the call targets."""
|
|
197
|
+
key = "query" if operation == "search" else "url"
|
|
198
|
+
target = kwargs.get(key)
|
|
199
|
+
if target is None and args:
|
|
200
|
+
target = args[0]
|
|
201
|
+
|
|
202
|
+
if isinstance(target, str):
|
|
203
|
+
attr = "firecrawl.query" if operation == "search" else "url.full"
|
|
204
|
+
return {attr: target}
|
|
205
|
+
if isinstance(target, (list, tuple)): # batch_scrape / extract url lists
|
|
206
|
+
return {"firecrawl.url_count": len(target)}
|
|
207
|
+
return {}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _result_count(payload: dict) -> Optional[int]:
|
|
211
|
+
data = payload.get("data")
|
|
212
|
+
if isinstance(data, list): # crawl / batch_scrape
|
|
213
|
+
return len(data)
|
|
214
|
+
if isinstance(payload.get("links"), list): # map
|
|
215
|
+
return len(payload["links"])
|
|
216
|
+
if payload.get("markdown") or payload.get("html"): # scrape (single doc)
|
|
217
|
+
return 1
|
|
218
|
+
# search responses expose web/news/images lists instead of `data`
|
|
219
|
+
result_lists = [
|
|
220
|
+
payload[k] for k in ("web", "news", "images") if isinstance(payload.get(k), list)
|
|
221
|
+
]
|
|
222
|
+
if result_lists:
|
|
223
|
+
return sum(len(lst) for lst in result_lists)
|
|
224
|
+
return None
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _extract_credits(payload: dict) -> Optional[int]:
|
|
228
|
+
for key in ("creditsUsed", "credits_used"):
|
|
229
|
+
if payload.get(key) is not None:
|
|
230
|
+
return int(payload[key])
|
|
231
|
+
meta = payload.get("metadata")
|
|
232
|
+
if isinstance(meta, dict):
|
|
233
|
+
for key in ("creditsUsed", "credits_used"):
|
|
234
|
+
if meta.get(key) is not None:
|
|
235
|
+
return int(meta[key])
|
|
236
|
+
return None
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def _as_dict(obj: Any) -> dict:
|
|
240
|
+
"""Firecrawl SDK returns pydantic models; normalize to a plain dict."""
|
|
241
|
+
if isinstance(obj, dict):
|
|
242
|
+
return obj
|
|
243
|
+
for attr in ("model_dump", "dict"):
|
|
244
|
+
fn = getattr(obj, attr, None)
|
|
245
|
+
if callable(fn):
|
|
246
|
+
try:
|
|
247
|
+
return fn()
|
|
248
|
+
except Exception:
|
|
249
|
+
pass
|
|
250
|
+
return {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Tests for FirecrawlInstrumentor.
|
|
2
|
+
|
|
3
|
+
We inject a fake `firecrawl` package that mirrors the real SDK layout: the v2
|
|
4
|
+
methods live on ``firecrawl.v2.client.FirecrawlClient``, and the unified
|
|
5
|
+
``firecrawl.Firecrawl`` client binds them onto each instance in ``__init__``
|
|
6
|
+
(exactly like firecrawl-py 4.x). This lets us drive the real patching path with
|
|
7
|
+
no network or real SDK.
|
|
8
|
+
|
|
9
|
+
We call `_instrument` rather than `.instrument()` so the test does not depend on
|
|
10
|
+
firecrawl-py being installed as a distribution (the public `.instrument()` does
|
|
11
|
+
a dependency check that would skip a fake module).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import sys
|
|
15
|
+
import types
|
|
16
|
+
|
|
17
|
+
import pytest
|
|
18
|
+
from opentelemetry.sdk.metrics import MeterProvider
|
|
19
|
+
from opentelemetry.sdk.metrics.export import InMemoryMetricReader
|
|
20
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
21
|
+
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
|
22
|
+
from opentelemetry.sdk.trace.export.in_memory_span_exporter import (
|
|
23
|
+
InMemorySpanExporter,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class MockDoc:
|
|
28
|
+
def __init__(self, **kw):
|
|
29
|
+
self.__dict__.update(kw)
|
|
30
|
+
|
|
31
|
+
def model_dump(self):
|
|
32
|
+
return dict(self.__dict__)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class _FirecrawlClient:
|
|
36
|
+
"""Stand-in for firecrawl.v2.client.FirecrawlClient."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, api_key=None):
|
|
39
|
+
self.api_key = api_key
|
|
40
|
+
|
|
41
|
+
def scrape(self, url, formats=None):
|
|
42
|
+
return MockDoc(markdown="# hello world", metadata={"credits_used": 3})
|
|
43
|
+
|
|
44
|
+
def search(self, query, limit=None):
|
|
45
|
+
return MockDoc(web=[{"url": "a"}, {"url": "b"}], news=[{"url": "c"}])
|
|
46
|
+
|
|
47
|
+
def crawl(self, url, limit=None):
|
|
48
|
+
return MockDoc(
|
|
49
|
+
status="completed",
|
|
50
|
+
total=2,
|
|
51
|
+
completed=2,
|
|
52
|
+
credits_used=12,
|
|
53
|
+
data=[{"markdown": "p1"}, {"markdown": "p2"}],
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
def map(self, url): # used to exercise the error path
|
|
57
|
+
raise RuntimeError("kaboom")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _install_fake_firecrawl():
|
|
61
|
+
"""Register a fake firecrawl package tree in sys.modules; return the root."""
|
|
62
|
+
root = types.ModuleType("firecrawl")
|
|
63
|
+
v2 = types.ModuleType("firecrawl.v2")
|
|
64
|
+
client_mod = types.ModuleType("firecrawl.v2.client")
|
|
65
|
+
client_mod.FirecrawlClient = _FirecrawlClient
|
|
66
|
+
v2.client = client_mod
|
|
67
|
+
|
|
68
|
+
class Firecrawl:
|
|
69
|
+
"""Unified client that binds v2 methods per-instance, like the real SDK."""
|
|
70
|
+
|
|
71
|
+
def __init__(self, api_key=None):
|
|
72
|
+
self._v2 = client_mod.FirecrawlClient(api_key=api_key)
|
|
73
|
+
self.scrape = self._v2.scrape
|
|
74
|
+
self.search = self._v2.search
|
|
75
|
+
self.crawl = self._v2.crawl
|
|
76
|
+
self.map = self._v2.map
|
|
77
|
+
|
|
78
|
+
root.Firecrawl = Firecrawl
|
|
79
|
+
root.v2 = v2
|
|
80
|
+
|
|
81
|
+
sys.modules["firecrawl"] = root
|
|
82
|
+
sys.modules["firecrawl.v2"] = v2
|
|
83
|
+
sys.modules["firecrawl.v2.client"] = client_mod
|
|
84
|
+
return root
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.fixture
|
|
88
|
+
def instrumented():
|
|
89
|
+
span_exporter = InMemorySpanExporter()
|
|
90
|
+
tracer_provider = TracerProvider()
|
|
91
|
+
tracer_provider.add_span_processor(SimpleSpanProcessor(span_exporter))
|
|
92
|
+
|
|
93
|
+
metric_reader = InMemoryMetricReader()
|
|
94
|
+
meter_provider = MeterProvider(metric_readers=[metric_reader])
|
|
95
|
+
|
|
96
|
+
firecrawl = _install_fake_firecrawl()
|
|
97
|
+
|
|
98
|
+
from firecrawl_otel import FirecrawlInstrumentor
|
|
99
|
+
|
|
100
|
+
instr = FirecrawlInstrumentor()
|
|
101
|
+
instr._instrument(
|
|
102
|
+
tracer_provider=tracer_provider, meter_provider=meter_provider
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# Client is created AFTER instrument(), mirroring the documented order.
|
|
106
|
+
yield firecrawl, span_exporter, metric_reader, instr
|
|
107
|
+
|
|
108
|
+
instr._uninstrument()
|
|
109
|
+
for name in ("firecrawl.v2.client", "firecrawl.v2", "firecrawl"):
|
|
110
|
+
sys.modules.pop(name, None)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _spans_by_name(exporter):
|
|
114
|
+
return {s.name: s for s in exporter.get_finished_spans()}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_scrape_span_attributes(instrumented):
|
|
118
|
+
firecrawl, spans_exporter, _, _ = instrumented
|
|
119
|
+
app = firecrawl.Firecrawl(api_key="fc-test")
|
|
120
|
+
app.scrape("https://example.com", formats=["markdown", "html"])
|
|
121
|
+
|
|
122
|
+
span = _spans_by_name(spans_exporter)["firecrawl.scrape"]
|
|
123
|
+
assert span.attributes["firecrawl.operation"] == "scrape"
|
|
124
|
+
assert span.attributes["firecrawl.formats"] == "markdown,html"
|
|
125
|
+
assert span.attributes["url.full"] == "https://example.com"
|
|
126
|
+
assert span.attributes["firecrawl.results"] == 1
|
|
127
|
+
assert span.attributes["firecrawl.credits_used"] == 3 # from metadata
|
|
128
|
+
assert span.status.status_code.name == "OK"
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_search_and_crawl(instrumented):
|
|
132
|
+
firecrawl, spans_exporter, _, _ = instrumented
|
|
133
|
+
app = firecrawl.Firecrawl(api_key="fc-test")
|
|
134
|
+
app.search("what is otel", limit=2)
|
|
135
|
+
app.crawl("https://example.com", limit=5)
|
|
136
|
+
|
|
137
|
+
spans = _spans_by_name(spans_exporter)
|
|
138
|
+
search = spans["firecrawl.search"]
|
|
139
|
+
assert search.attributes["firecrawl.query"] == "what is otel"
|
|
140
|
+
assert search.attributes["firecrawl.results"] == 3 # 2 web + 1 news
|
|
141
|
+
|
|
142
|
+
crawl = spans["firecrawl.crawl"]
|
|
143
|
+
assert crawl.attributes["firecrawl.results"] == 2
|
|
144
|
+
assert crawl.attributes["firecrawl.credits_used"] == 12 # from credits_used
|
|
145
|
+
assert crawl.attributes["firecrawl.status"] == "completed"
|
|
146
|
+
assert crawl.attributes["firecrawl.total"] == 2
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def test_error_path_sets_error_status(instrumented):
|
|
150
|
+
firecrawl, spans_exporter, _, _ = instrumented
|
|
151
|
+
app = firecrawl.Firecrawl(api_key="fc-test")
|
|
152
|
+
with pytest.raises(RuntimeError):
|
|
153
|
+
app.map("https://example.com")
|
|
154
|
+
|
|
155
|
+
span = _spans_by_name(spans_exporter)["firecrawl.map"]
|
|
156
|
+
assert span.status.status_code.name == "ERROR"
|
|
157
|
+
assert len(span.events) >= 1 # recorded exception
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def test_metrics_recorded(instrumented):
|
|
161
|
+
firecrawl, _, metric_reader, _ = instrumented
|
|
162
|
+
app = firecrawl.Firecrawl(api_key="fc-test")
|
|
163
|
+
app.scrape("https://example.com", formats=["markdown"])
|
|
164
|
+
app.crawl("https://example.com", limit=5)
|
|
165
|
+
|
|
166
|
+
metric_names = set()
|
|
167
|
+
total_requests = 0
|
|
168
|
+
for rm in metric_reader.get_metrics_data().resource_metrics:
|
|
169
|
+
for sm in rm.scope_metrics:
|
|
170
|
+
for metric in sm.metrics:
|
|
171
|
+
metric_names.add(metric.name)
|
|
172
|
+
if metric.name == "firecrawl.requests":
|
|
173
|
+
total_requests += sum(p.value for p in metric.data.data_points)
|
|
174
|
+
|
|
175
|
+
assert "firecrawl.requests" in metric_names
|
|
176
|
+
assert "firecrawl.request.duration" in metric_names
|
|
177
|
+
assert "firecrawl.credits.used" in metric_names
|
|
178
|
+
assert total_requests == 2
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def test_uninstrument_stops_tracing(instrumented):
|
|
182
|
+
firecrawl, spans_exporter, _, instr = instrumented
|
|
183
|
+
instr._uninstrument()
|
|
184
|
+
|
|
185
|
+
# A client created after uninstrument binds the original, unwrapped methods.
|
|
186
|
+
app = firecrawl.Firecrawl(api_key="fc-test")
|
|
187
|
+
app.scrape("https://example.com")
|
|
188
|
+
assert "firecrawl.scrape" not in _spans_by_name(spans_exporter)
|